943,545 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Marked Solved
  • Views: 2022
  • VB.NET RSS
Sep 23rd, 2008
0

Letter Grade Array

Expand Post »
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.


vb Syntax (Toggle Plain Text)
  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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
bpacheco1227 is offline Offline
58 posts
since Jul 2007
Sep 23rd, 2008
1

Re: Letter Grade Array

Here you made mistake.

change
VB Syntax (Toggle Plain Text)
  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

VB Syntax (Toggle Plain Text)
  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
Reputation Points: 44
Solved Threads: 101
Posting Pro
selvaganapathy is offline Offline
547 posts
since Feb 2008
Sep 23rd, 2008
0

Re: Letter Grade Array

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.
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
bpacheco1227 is offline Offline
58 posts
since Jul 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Embedding Batch Files?
Next Thread in VB.NET Forum Timeline: ReportViewer.. Help me pleeeeease





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC