kay finally got something on my clipboard
private double Average(int[] avrArray)
//sets up a double method to obtain the average of test scores
{
double average;
//creates a value to store avrArray's average
double value = 0.0;
//creates a value to store the sum of avrArray's contents
for (int index = 0; index < avrArray.Length; index++)
{
value += avrArray[index];
}
//obtains values from avrArray
average = (double) value / avrArray.Length;
//finds the average of the values and stores it in average
return average;
//returns the average to the new double
}
private int Lowest(int[] lowArray)
//new int method lowest with arguement lowArray
{
int lowest = lowArray[0];
//sets up the basic value of lowest as lowArray's first subscript
for (int index = 0; index < lowArray.Length; index++)
// finds the lowest value of lowarray, stores it in int lowest
{
if (lowArray[index] < lowest)
//checks if a certain subscript of lowarray is the lowest
{
lowest = lowArray[index];
//assigns the lowest quantity found to int lowest
}
}
return lowest;
//returns lowest to the method
}
private int Highest(int[] highArray)
//pretty much same thing as last method except the highest number
{
int highest = highArray[0];
for(int index = 0; index < highArray.Length; index++)
{
if (highArray[index] > highest)
{
highest = highArray[index];
}
}
return highest;
}
private void scorebutton_Click(object sender, EventArgs e)
{
const int size = 5;
//constant int for scores array
int[] scores = new int[size];
//new int array for scores
int index = 0;
//keeps index at a cool 0
int highscore;
int lowscore;
double avrscore;
//sets up values for new methods used later
StreamReader inputFile;
inputFile = File.OpenText("scores.txt");
//opens file scores.txt from the bin -> debug
while (!inputFile.EndOfStream && index < scores.Length)
{
scores[index] = int.Parse(inputFile.ReadLine());
index++;
}
//reads out scores from file and parses them for the score array, adds to index
inputFile.Close();
//closes readable file
foreach (int str in scores)
{
scorebox.Items.Add(str);
}
//adds items to the scorebox for everything in the score array
highscore = Highest(scores);
lowscore = Lowest(scores);
avrscore = Average(scores);
//assigns values of scores array through various methods to stated ints
highlabel.Text = highscore.ToString();
lowlabel.Text = lowscore.ToString();
averagelabel.Text = avrscore.ToString();
//strings values and puts them into text!
}
private void exit_Click(object sender, EventArgs e)
{
this.Close();
}
}
}