my assignment is to retrieve data from a txt file and output how many tests were input, average of all the tests, and then list the letter grade beside each text

what i have so far:

private StreamReader strRead;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            int[] gradeArray = new int[24];  // array to hold grades
            string gradeValue = "";           // string to hold current grade;
            strRead = new StreamReader("Grades.txt");  // streamreader for input file
            int traverseGradeArray = 0;       // index used for gradeArray.
            int averageGrades = 0;
            int totalGrades = 0;
            int numberofGrades = 0;


            // initialize gradeArray elements to -1
            for (int i = 0; i < 24; i++)
            {
                gradeArray[i] = -1;
            }  // for int i

            // while not at the end of the file
            while ((gradeValue = fil.ReadLine()) != null)
            {
                // set current gradeArray value to what was read from file.
                gradeArray[traverseGradeArray] = Convert.ToInt32(gradeValue);

                // increment element counter
                traverseGradeArray++;

            }  // while not at the end of the file

            // output contents of gradeArray to listBox

            for (int i = 0; i < 24; i++)


            totalGrades = totalGrades + gradeArray[i];
            averageGrades = totalGrades / 24;

            listBoxOutput.Items.Add(averageGrades);

            gradeArray = new int[24];

            totalGrades = gradeArray.Length;
            listBoxOutput.Items.Add(totalGrades);

            for (int i = 0; i < 24; i++)
                if (gradeArray[i] >= 91)
                {
                    this.listBoxOutput.Text = "A";
                }
        }

stuck & stressed..PLEASE HELP!

Let me see if I understand you correctly.
First you want to read to a text-file to get and treat every line as a number (which you call a grade), am I correct? What I don't understand is where you get the number 24 from, but what I would do to read the file is as following:

List<int> gradeArray = new List<int>();
StreamReader strRead = new StreamReader("Grades.txt");
while ((gradeValue = strRead.ReadLine()) != null)
    gradeArray.Add(Convert.ToInt32(gradeValue));
strRead.Close(); //Important

gradeArray will now contain the grades.
How many tests where input is as simple as gradeArray.Count , the average is gradeArray.Sum() / gradeArray.Count (using LINQ).
To order the grades do the following

List<int> orderedGrades = from grade in gradeArray
                          orderby grade
                          select grade;

The last example also uses LINQ.
Note, this code hasn't been tested.

Thanks. I actually do not have to sort & there are 20 grades in the Grades.txt not 24, sorry.

To more clarify:

I have to display in the listbox (which is what I'm having problems with)

"There were "#' exams."
"Mean: '#'."
"Standard Deviation: '#'."

Score Grade
91 A

etc etc

I have to display in the listbox (which is what I'm having problems with)

"There were "#' exams."
"Mean: '#'."
"Standard Deviation: '#'."

Score Grade
91 A

etc etc

Sorry, than I can't help you. I'm not that good in English and I don't even understand what "Mean" and "Standard Deviation" is supposed to hold of value. And are you trying to calculate which grade should represent what score? Or is that what you read from the text-file?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.