I need to write a program that reads in a set of test scores from a inputbox then displays them in a list box with a corresponding letter grade. Then from there display the Standard devation, the Mean, and the number of the test scores. I cant seem to get the right output from the input box to the lst box and so on.

Below is what I have thus far I cant really see where I am goin wrong. Any help would be a major plus. Thank you!

Public Class Form1

    Private Sub btnCompute_Click(sender As Object, e As EventArgs) Handles btnCompute.Click
        Dim sngTotal As Single
        Dim intNumScores As Integer
        Dim strInput As String
        Dim Count As Integer
        Dim intCounter As Integer
        Dim grade As String
        Dim mean, total As Double
        Dim stdDev As Double = 0


        strInput = InputBox("Please Enter Test Scores", "Enter Score")

        sngTotal = 100
        Count = 0


        For intCounter = 1 To 10 Step 1
            strInput = InputBox("Enter the value for test score " _
            & Count.ToString, "Test Score Needed")
            sngTotal = (strInput)
        Next


        stdDev = stdDev / (intNumScores)
        stdDev = Math.Sqrt(stdDev)
        txtMean.Text = FormatNumber(mean)
        txtSD.Text = FormatNumber(stdDev)
        txtExams.Text = FormatNumber(total)


        If intNumScores >= (mean + (1.5 * stdDev)) Then
            grade = "A"
        ElseIf (mean + (0.5 * stdDev)) <= intNumScores And intNumScores < (mean + (1.5 * stdDev)) Then
            grade = "B"
        ElseIf (mean - (0.5 * stdDev)) <= intNumScores And intNumScores < (mean + (0.5 * stdDev)) Then
            grade = "C"
        ElseIf (mean - (1.5 * stdDev)) <= intNumScores And intNumScores < (mean - (0.5 * stdDev)) Then
            grade = "D"
        ElseIf intNumScores < (1.5 * stdDev) - mean Then
            grade = "F"
        End If

        lstScores.Items.Add(lstScores.Text & intNumScores & "Grade: " & grade)
        Count += 1

    End Sub

    Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
        Me.Close()
    End Sub
End Class

To start with, you do

strInput = InputBox("Please Enter Test Scores", "Enter Score")

which prompts the user to enter the test scores. Then (supposedly once the user enters the scores) you ask for 10 more scores in

For intCounter = 1 To 10 Step 1

Before the loop you set sngTotal to 100 although I do not know why. Then in the loop you replace the value of sngTotal with the statement

sngTotal = (strInput)

That's not going to accomplish much except generate an error because you are assigning a string to a numeric. And even if it worked you are just throwing away the first nine values entered.

Try to write out what you want to do in pseudo-code before you write actual code.

I fixed everything else from the above code but I am still not getting the grade next to the corresponding number in the list box. also the mean and Standard Dev seem to be alittle messed up. Any suggesttions?

Public Class Form1

    Private Sub btnCompute_Click(sender As Object, e As EventArgs) Handles btnCompute.Click
        Dim Total As Single
        Dim intNumScores As Integer
        Dim strInput As String
        Dim Count As Integer
        Dim grade As String
        Dim mean As Double
        Dim stdDev As Double = 0

        Do
            strInput = InputBox(" Enter Exam Scores ")
            If intNumScores <> -1 Then
                lstScores.Items.Add(strInput)
                Count = Count + 1
                Total += intNumScores
            End If
        Loop Until Count = 10

        stdDev = stdDev / (Count)
        stdDev = Math.Sqrt(stdDev)
        txtMean.Text = strInput / Count
        txtSD.Text = Math.Sqrt(strInput)
        txtExams.Text = Count


        If strInput >= (mean + (1.5 * stdDev)) Then
            grade = "A"
        ElseIf (mean + (0.5 * stdDev)) <= strInput And strInput < (mean + (1.5 * stdDev)) Then
            grade = "B"
        ElseIf (mean - (0.5 * stdDev)) <= strInput And strInput < (mean + (0.5 * stdDev)) Then
            grade = "C"
        ElseIf (mean - (1.5 * stdDev)) <= strInput And strInput < (mean - (0.5 * stdDev)) Then
            grade = "D"
        ElseIf strInput < (1.5 * stdDev) - mean Then
            grade = "F"
        End If

        lstScores.Items.Add(lstScores.Text & strInput & " " & "Grade: " & grade)
        Count += 1

    End Sub

    Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
        Me.Close()
    End Sub
End Class

The standard deviation is the square root of the variance and the variance is the squared differences from the mean. So to get the variance you must

  1. calculate the mean (average) of the numbers
  2. subtract the mean from each number and square it
  3. find the mean of the squared differences

So if you have five test scores with values 98, 57, 72, 88 and 91 the average is

(98 + 57 + 72 + 88 + 91) / 5 = 81.2

The differences from the mean are

16.8, -24.2, -9.2, 6.8, 9.8

The variance is

(16.8**2 + -24.2**2 + -9.2**2 + 6.8**2 + 9.8**2) / 5 =  218.96

and the standard deviation is

SQRT(218.96) = 14.797

You can see that you can't calculate the variance until you know the mean, and you won't know the mean until you have input all of the numbers. So that tells you that you must keep all of the scores in an array so that you can step through them again. Give this a thought and see how you make out. I'll check bak in a while.

That is where I am having my biggest problem the array for storing the numbers then having the numbers enetered calculated correctly any pointers or examples for an array that could help with this?

If you only need the values available for the duration of the calculation (once the button_click exits the variables can "go away") then you can declare the array in the handler, otherwise you can declare it at the class level. You would do something like

Private Sub btnCompute_Click(sender As Object, e As EventArgs) Handles btnCompute.Click

    Dim scores(4) As Single
    Dim numScores As Integer = 5
    Dim total As Single = 0.0
    Dim i As Integer = 0

    Do While i <= 5

        Dim prompt As String = "Enter score " & i & " of " & numscores)
        Dim str As String = InputBox(prompt)

        'Here you should verify that what the user entered is a number
        '1) numeric
        '2) a number between 0 and 100
        'If it fails the validation then you should tell the user why.
        'If it passes then you can save the score in the array and add
        '1 to i.

    Loop

To add it to the array you just do

scores(i-1) = CSng(str)
total += scores(i-1)
i += 1

You have to use i-1 as the index because the indices run from 0 to 4 and we have i running from 1 to 5 (you don't want to ask the user, for example, to enter score 0 because that's not how people count).

Once you are done getting all the valid scores you'll need another loop to calculate the variance (which you need to find the standard deviation).

Really at a loss here I have tried various things with the array and input box cant seem to get it to work still and is due by midnight any other help would be greatly appericated

At this point, aside from giving you the solution, there is not much else I can do. As has been said here many times before, we will help but we will not do your homework for you.

This article has been dead for over six months. Start a new discussion instead.