0

After entering an "A" worthy grade the case select is still returning an "F". I know it's simple but what's wrong here?

'perform calculations
totalTest = (testScore1 + testScore2 + testScore3) / 3 * testWeight
totalLab = (labScore1 + labScore2 + labScore3 + labScore4 + labScore5) / 5 * labWeight
totalQuiz = (quizScore1 + quizScore2 + quizScore3 + quizScore4) / 4 * quizWeight
totalFinal = finalScore * finalWeight

totalGrades = totalTest + totalLab + totalQuiz + totalFinal

Select Case grade
    Case 90 To 100
        letterGradeLabel.Text = "A"
    Case 80 To 89.99
        letterGradeLabel.Text = "B"
    Case 70 To 79.99
        letterGradeLabel.Text = "C"
    Case 60 To 69.99
        letterGradeLabel.Text = "D"
    Case Else
        letterGradeLabel.Text = "F"
End Select

'display average and letter grade
finalGradeLabel.Text = totalGrades.ToString
GSerg
  • 76,472
  • 17
  • 159
  • 346
Billyin4c
  • 13
  • 5
  • Shouldn't it be `Select Case totalGrades` instead of `Select Case grade`? – Bill Tür stands with Ukraine Sep 09 '17 at 20:29
  • Thanks! Of course it should be. Knew it was right under my nose – Billyin4c Sep 09 '17 at 20:36
  • 3
    FWIW, you would catch this much sooner if you had used `Option Explicit` to block implicit declaration of variables. I highly encourage using it to help avoid those kind of errors. – this Sep 09 '17 at 21:09
  • 3
    I don't know the values of your weights, but if a student comes up with a total grade of 89.995 they are going to be unhappy with their grade. There is no reason not to use 80 to 90 for B, as the 90 for A will catch it first, and anything slightly less will be in B and not fall through to F. Also if rounding allows a total grade higher than 100, you'd get an F. – Patrick Sep 10 '17 at 16:06
  • 1
    Alternatively, use `Case Is >= 90` for A, `Case Is >= 80` for B, and so on. – Craig Sep 11 '17 at 14:27

0 Answers0