Hey all.

I am making an application through 10 exam scores (integers 0-100) are entered into separate text boxes within a group box, and are analyzed with the click of a button. The list box should then display the mean, standard deviation, and the list of scores and corresponding grades. According to the bell-curve, the letter grades are determined as follows:

ES >= m + 1.5s = A
m + 0.5s <= ES < m + 1.5s = B
m – 0.5s <= ES < m + 0.5s = C
m – 1.5s <= ES <= m – 0.5s = D
ES < m – 1.5s = F

Here is the code I have so far:

Public Class Form1

    Private Sub btnAnalyze_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAnalyze.Click
        Dim Score(9), ES As Integer
        Dim stdDeviation, mean As Double
        Dim Grade(9) As String
        Dim fmtstr As String = "{0, -15} {1, 15}"

        'Store scores into array
        Score(0) = TextBox1.Text
        Score(1) = TextBox2.Text
        Score(2) = TextBox3.Text
        Score(3) = TextBox4.Text
        Score(4) = TextBox5.Text
        Score(5) = TextBox6.Text
        Score(6) = TextBox7.Text
        Score(7) = TextBox8.Text
        Score(8) = TextBox9.Text
        Score(9) = TextBox10.Text

        'Determine the mean
        mean = (Score(0) + Score(1) + Score(2) + Score(3) + Score(4) + Score(5) + Score(6) + Score(7) _
        + Score(8) + Score(9)) / 10

        'Determine the standard deviation
        stdDeviation = System.Math.Sqrt((((Score(0) - mean) ^ 2) + ((Score(1) - mean) ^ 2) + ((Score(2) - mean) ^ 2) + ((Score(3) - mean) ^ 2) + ((Score(4) - mean) ^ 2) + _
                                         (Score(5) - mean) ^ 2 + ((Score(6) - mean) ^ 2) + ((Score(7) - mean) ^ 2) + ((Score(8) - mean) ^ 2) + ((Score(9) - mean) ^ 2)))/10))

        'Determine the letter grades and store them into an array
        For i = 0 To 9
            Score(i) = ES
            If ES >= mean + (1.5 * stdDeviation) Then
                Grade(i) = "A"
            ElseIf mean + (0.5 * stdDeviation) <= ES < mean + (1.5 * stdDeviation) Then
                Grade(i) = "B"
            ElseIf mean - (0.5 * stdDeviation) <= ES < mean + (0.5 * stdDeviation) Then
                Grade(i) = "C"
            ElseIf mean - (1.5 * stdDeviation) <= ES <= mean - (0.5 * stdDeviation) Then
                Grade(i) = "D"
            ElseIf ES < mean - (1.5 * stdDeviation) Then
                Grade(i) = "F"
            End If
        Next

        'Display analysis of grades
        Display.Items.Add(Str("There were 10 exams."))
        Display.Items.Add(Str("Mean:" & CStr(mean)))
        Display.Items.Add(Str("Standard Deviation:" & CStr(stdDeviation)))
        For i = 0 To 9
            Display.Items.Add(String.Format(fmtstr, CStr(Score(i)), Grade(i)))
        Next

    End Sub
End Class

The syntax error is on line 27 at the end of the stdDeviation equation. It reads "end of statement expected", and I have no clue what to do about it. What is the problem, and how can I resolve it? Also, is there any way I could have structured the program so that it accomplishes this task more efficiently. I am new to programming, and I would really appreciate any help I can get.

I went through and made some changes. Can't help you on the last part with the ES variable. Been to long since I dealt with statistics and have found no need for bell shape curves. That last block does need some modifying.

Main changes was to get rid of the hard coded numbers. Since you have your textboxes in a group box, which is good, you can iterate through all the controls in the groupbox to determine how many text boxes there are. When iterating through them check that the typeof of control is a text box. That will cause it to skip any labels or other controls.

I Put your math calcs in a for loop. It may be better to break down long formulas with seperate calcs instead of one big one. It can make it easier to read and debug.

You had a mix up with your (). That was giving you the end of statement error. probably had one in the wrong place. Perfect example to break down a formula.

Private Sub btnAnalyze_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAnalyze.Click
        'The hard coded values is never a good idea unless you like to
        'change your code all the time.  This makes a mod so it doesn't
        'matter how many textboxes you have.

        Dim ES As Integer
        Dim stdDeviation, mean As Double
        Dim fmtstr As String = "{0, -15} {1, 15}"

        'You can initialy set the arrays as new empty arrays.
        'Doing this will cause the code to run through with 
        'no errors even if there are no textboxes.
        Dim Score() As Integer = New Integer() {}
        Dim Grade() As Integer = New Integer() {}


        'Instead of hard coding the number of textboxes.  
        'Iterate through all the controls in the GroupBox.  If the
        'control is a text box then increase the score array and set  
        'the value
        For i = 0 To GroupBoxScores.Controls.Count - 1
            If TypeOf GroupBoxScores.Controls(i) Is TextBox Then
                'The text box value needs to be validated
                'Increase the size of the array by 1.
                'Ubound will return the upperbound
                'GetLength(0) will return the lenght of the first
                'demension.
                'If get length returns 2 then redimming it to 2 will
                'now cause the array to have three values.
                'Use preserve so you don't erase the existing values
                'otherwise omit it.
                ReDim Preserve Score(Score.GetLength(0))
                Score(UBound(Score)) = CInt(GroupBoxScores.Controls(i).Text)
            End If
        Next

        'If there were textboxes in the panel then set the grade 
        'array to the same length.
        If Score.GetLength(0) > 0 Then ReDim Grade(UBound(Score))

        'Next two blocks put your calculation in a for loop.
        'For readability only.

        'Determine the mean
        For i = 0 To UBound(Score)
            mean += Score(i)
        Next
        mean /= Score.GetLength(0)

        'Determine the Standard Deviation
        For i = 0 To UBound(Score)
            stdDeviation += Math.Pow(Score(i) - mean, 2)
        Next
        stdDeviation = Math.Sqrt(stdDeviation / Score.GetLength(0))

        'Determine the letter grades and store them into an array
        For i = 0 To UBound(Score)
            ' You are setting the score to 0 at this line
            'Missing a calculation?
            Score(i) = ES

            'This has some issues.
            'Its been to long since I dealt with statistics so I don't 
            'know what ES is supposed to stand for.  
            'There is going to be an issue with the < behind <= ES.
            If ES >= mean + (1.5 * stdDeviation) Then
                Grade(i) = "A"
            ElseIf mean + (0.5 * stdDeviation) <= ES < mean + (1.5 * stdDeviation) Then
                Grade(i) = "B"
            ElseIf mean - (0.5 * stdDeviation) <= ES < mean + (0.5 * stdDeviation) Then
                Grade(i) = "C"
            ElseIf mean - (1.5 * stdDeviation) <= ES <= mean - (0.5 * stdDeviation) Then
                Grade(i) = "D"
            ElseIf ES < mean - (1.5 * stdDeviation) Then
                Grade(i) = "F"
            End If
        Next

        'Removed your Str function.
        'Thats to convert a number to a string.
        'A string is already a string so no need.

        'Display analysis of grades
        Display.Items.Add("There were " & Score.GetLength(0) & " exams.")
        Display.Items.Add("Mean:" & CStr(mean))
        Display.Items.Add("Standard Deviation:" & CStr(stdDeviation))
        For i = 0 To UBound(Score)
            Display.Items.Add(String.Format(fmtstr, CStr(Score(i)), Grade(i)))
        Next

    End Sub

Unhnd Exception, thanks so much for helping me out again. I really appreciate it. As for the last block, I think I should be able to fix it with the addition of the AND operator i.e. ES >= mean + (0.5 * stdDeviaiton) AND ES < mean + (1.5 * stdDeviation)

This question has already been answered. Start a new discussion instead.