I need to average the numbers in the array and display and also detemine the letter grade and display. I've managed to average the numbers but I am unable to display the lettergrade, (won't compile) I think it has to do with "Average Grade" being a constant string

This is the error I get "Conversion from string "Average grade: " to type 'Double' is not valid."

Please Help! Thank You.
:'(

Public Class Form1
    Dim grades(0 To 4) As Integer
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim prompt, title As String
        Dim i As Short
        prompt = "Enter the grade"
        For i = 0 To UBound(grades)
            title = "Grade " & (i + 1)
            grades(i) = InputBox(prompt, title)
        Next

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim letterGrade As String
        Dim result As String
        Dim i As Short
        Dim total As Single = 0
        result = "High temperatures for the week:" & vbCrLf & vbCrLf
        For i = 0 To UBound(grades)
            result = result & "Day " & (i + 1) & vbTab & _
            grades(i) & vbCrLf
            total = total + grades(i)
        Next
        result = result & vbCrLf & _
        "Average grade: " & Format(total / 5, "0.0")
        If "Average grade: " >= 90 Then
            letterGrade = "A"
        ElseIf "Average grade: " >= 80 Then
            letterGrade = "B"
        ElseIf "Average grade: " >= 70 Then
            letterGrade = "C"
        ElseIf "Average grade: " >= 60 Then
            letterGrade = "D"
        Else
            letterGrade = "F"
        End If
        result = result & vbCrLf & _
        "Letter Grade: " & Format(letterGrade)
        TextBox1.Text = result
    End Sub

Here you made mistake.

change

If "Average grade: " >= 90 Then
            letterGrade = "A"
        ElseIf "Average grade: " >= 80 Then
            letterGrade = "B"
        ElseIf "Average grade: " >= 70 Then
            letterGrade = "C"
        ElseIf "Average grade: " >= 60 Then
            letterGrade = "D"
        Else
            letterGrade = "F"
        End If

as

If total >= 90 Then
            letterGrade = "A"
        ElseIf total >= 80 Then
            letterGrade = "B"
        ElseIf total >= 70 Then
            letterGrade = "C"
        ElseIf total >= 60 Then
            letterGrade = "D"
        Else
            letterGrade = "F"
        End If
commented: a great help +2

Thanks the helped a little but I needed the letter grade for the average not the total. I figured it out though, Thanks for the push in the right direction.

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.