I am having trouble with the following code for the following problem please help???: The code I have come up with will not work
Create an application, save as GradeCalculator, that has the user press a EnterGrades button and enter in values in an input box. As you are entering values, they should be stored in an array.
When you are finished entering grades, have the cancel button return you to the program.
There should be a second button, CalcAvg, that calculates the average score and displays the grades and their average in a label on the form.
Code:
CODE
Public Class mainForm
'module-level array
Private gradeValues () As String
Private Sub exitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles exitButton.Click
Me.Close()
End Sub
Private Sub enterButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles enterButton.Click
'allows users to enter grades
' stores the grades in the module-level
' gradeValues array
For subscript As Integer = 0 To gradeValues.Length - 1
gradeValues(subscript)=
InputBox("Grade Value:", "Grade Values")
Next subscript
End Sub
Private Sub calculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles calculateButton.Click
'displays grades and calculated average grade
Dim gradeValues() As Integer = {}
Dim gradeAccumulator As Integer
Dim averageGrade As Double
' accumulates total grades
For Each grade As Integer In gradeValues
gradeAccumulator = gradeAccumulator + grade
Next grade
' displays grades and calculates average grade
For Each grade As String In gradeValues
gradeLabel.Text = gradeLabel.Text & grade & ControlChars.NewLine
Next grade
averageGrade = gradeAccumulator / gradeValues.Length
avggradeLabel.Text = Convert.ToString(averageGrade)
End Sub
End Class