I am trying to figure out how to write the code to change the number grade to a letter grade then count the letter grades and show how many of each letter in a list box. I need someone to explain this to me and explain what I am doing wrong. This is the code that I have so far and this is the assignment.
Twenty scores, each between 0 and 100, are given in a text file “data.txt”. Write a program that - reads scores from this file into an array when the form is loaded - compute and display the number of scores above average in a text box (when “Number of Scores Above Average” button is clicked) - displays all scores in a list box (when “Show All Scores” button is clicked) - displays the number of A’s (scores 90 to 100), B’s (scores 80 to 89), C’s (scores 70 to 79), D’s (scores 60 to 69), and F’s (59 and below) in another list box (when “Show Letter Grades” button is clicked)
Public Class Scores Dim Scores() As String Private Sub Scores_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Scores = IO.File.ReadAllLines("Scores.txt") End Sub Private Sub btnAbove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAbove.Click Dim num As Integer = 0 For i As Integer = 0 To Scores.Count - 1 If CDbl(Scores(i)) >= 80 Then num += 1 End If Next txtNumAbove.Text = " The Number Of Scores Above Average Is " & num End Sub Private Sub btnShowAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShowAll.Click For Each score As String In Scores lstAllScores.Items.Add(score) Next End Sub Private Sub btnLetter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLetter.Click Dim letter As String = "" Dim count As Integer = 0 For Each score2 As Integer In Scores If score2 >= 90 Then letter = "A" ElseIf score2 >= 80 Then letter = "B" ElseIf score2 > 70 Then letter = "C" ElseIf score2 > 60 Then letter = "D" ElseIf score2 < 59 Then letter = "F" End If Next For i As Integer = 0 To letter.Count - 1 count += 1 Next lstLetterGrade.Items.Add(letter) End Sub