Letter Grade Array

Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jul 2007
Posts: 58
Reputation: bpacheco1227 is an unknown quantity at this point 
Solved Threads: 0
bpacheco1227 bpacheco1227 is offline Offline
Junior Poster in Training

Letter Grade Array

 
0
  #1
Sep 23rd, 2008
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.


  1. Public Class Form1
  2. Dim grades(0 To 4) As Integer
  3. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  4. Dim prompt, title As String
  5. Dim i As Short
  6. prompt = "Enter the grade"
  7. For i = 0 To UBound(grades)
  8. title = "Grade " & (i + 1)
  9. grades(i) = InputBox(prompt, title)
  10. Next
  11.  
  12. End Sub
  13.  
  14. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  15. Dim letterGrade As String
  16. Dim result As String
  17. Dim i As Short
  18. Dim total As Single = 0
  19. result = "High temperatures for the week:" & vbCrLf & vbCrLf
  20. For i = 0 To UBound(grades)
  21. result = result & "Day " & (i + 1) & vbTab & _
  22. grades(i) & vbCrLf
  23. total = total + grades(i)
  24. Next
  25. result = result & vbCrLf & _
  26. "Average grade: " & Format(total / 5, "0.0")
  27. If "Average grade: " >= 90 Then
  28. letterGrade = "A"
  29. ElseIf "Average grade: " >= 80 Then
  30. letterGrade = "B"
  31. ElseIf "Average grade: " >= 70 Then
  32. letterGrade = "C"
  33. ElseIf "Average grade: " >= 60 Then
  34. letterGrade = "D"
  35. Else
  36. letterGrade = "F"
  37. End If
  38. result = result & vbCrLf & _
  39. "Letter Grade: " & Format(letterGrade)
  40. TextBox1.Text = result
  41. End Sub
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 509
Reputation: selvaganapathy is an unknown quantity at this point 
Solved Threads: 88
selvaganapathy's Avatar
selvaganapathy selvaganapathy is offline Offline
Posting Pro

Re: Letter Grade Array

 
1
  #2
Sep 23rd, 2008
Here you made mistake.

change
  1. If "Average grade: " >= 90 Then
  2. letterGrade = "A"
  3. ElseIf "Average grade: " >= 80 Then
  4. letterGrade = "B"
  5. ElseIf "Average grade: " >= 70 Then
  6. letterGrade = "C"
  7. ElseIf "Average grade: " >= 60 Then
  8. letterGrade = "D"
  9. Else
  10. letterGrade = "F"
  11. End If

as

  1. If total >= 90 Then
  2. letterGrade = "A"
  3. ElseIf total >= 80 Then
  4. letterGrade = "B"
  5. ElseIf total >= 70 Then
  6. letterGrade = "C"
  7. ElseIf total >= 60 Then
  8. letterGrade = "D"
  9. Else
  10. letterGrade = "F"
  11. End If
KSG
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 58
Reputation: bpacheco1227 is an unknown quantity at this point 
Solved Threads: 0
bpacheco1227 bpacheco1227 is offline Offline
Junior Poster in Training

Re: Letter Grade Array

 
0
  #3
Sep 23rd, 2008
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.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC