จากโค้ดโปรแกรม ขั้นตอนแรกจะมีเมนูให้เลือกโดย
กด 1. Input and show grade
กด 2. Max and SecondaryMax score
กด 3. Min and SecondaryMin score
กด 4. Average score
กด 5. Show Frequency of each grade
Module Module1
Sub Main()
'Dim y As String
Dim x As Integer
Dim i As Integer
Dim score As Integer
Dim NumF, NumD, NumDD, NumA As Integer
Dim max, min, max2, min2, sum As Integer
max = 0
min = 100
Dim avg As Double
While x <> 6
Console.WriteLine(" ")
Console.WriteLine("Menu")
Console.WriteLine("*****************************")
Console.WriteLine("1. Input and show grade")
Console.WriteLine("2. Max and SecondaryMax score")
Console.WriteLine("3. Min and SecondaryMin score")
Console.WriteLine("4. Average score")
Console.WriteLine("5. Show Frequency of each grade")
'Console.WriteLine("6. Enter Exit")
Console.WriteLine("Enter choice : ")
x = Console.ReadLine
If x = 1 Then
Console.WriteLine("Input and show grade")
For i = 1 To 10 Step 1
'รับค่า
Console.Write("Enter int score no :" & i & " ")
score = Console.ReadLine
While score < 0 Or score > 100
Console.WriteLine("Invalid")
Console.Write("Enter int score no :" & i & " ")
score = Console.ReadLine
End While
sum = sum + score
Select Case score
Case 0 To 50
Console.WriteLine("F")
NumF += 1 'นับสะสมทีละ1
'NumF = NumF + 1'
Case 51 To 60
Console.WriteLine("D")
NumD += 1
Case 61 To 70
Console.WriteLine("D+")
NumDD += 1
Case 71 To 100
Console.WriteLine("A")
NumA += 1
End Select
Next
End If
If x = 2 Then
Console.WriteLine("Max and SecondaryMax score")
Console.WriteLine("- - - - - - - - - - - - - -")
If score > max Then
max2 = max
max = score
ElseIf score > max2 Then
max2 = score
End If
End If
If x = 3 Then
Console.WriteLine("Min and SecondaryMin score")
Console.WriteLine("- - - - - - - - - - - - - -")
If score < min Then
min2 = min
min = score
ElseIf score < min2 Then
min2 = score
End If
End If
If x = 4 Then
Console.WriteLine("Average score")
Console.WriteLine("- - - - - - - - - - - - - - -")
avg = sum / 10
Console.WriteLine("Average score = " & avg)
ElseIf x = 5 Then
Console.WriteLine("Show Frequency of each grade")
Console.WriteLine("- - - - - - - - - - - - - - -")
Console.WriteLine("Number of grade A = " & NumA)
Console.WriteLine("Number of grade D+ = " & NumDD)
Console.WriteLine("Number of grade D = " & NumD)
Console.WriteLine("Number of grade F = " & NumF)
End If
End While
End Sub
End Module