ช่วยดูโค้ดให้หน่อยค่ะ ใส่จำนวนไปแล้วเมื่อกดเมนูจะเรียกดูค่า max และ min มันไม่ขึ้น
Code (VB.NET)
Module Module1
Sub Main()
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("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("- - - - - - - - - - - - - -")
ElseIf 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
ปล.
ตัวแปร max คือ ค่าที่มากที่สุด
ตัวแปร max2 คือ ค่าที่มากรองลงมา
ตัวแปร min คือ ค่าที่น้อยที่สุด
ตัวแปร min2 คือ ค่าที่น้อยที่สุดรองลงมา