I'm working on a project that has the user input 15 grades, calculates the average, and finds the maximum and minimum values. The average and maximum calculations work but I can't figure out how to get the minimum value. Here is my code so far:
Public
Sub DetermineClassAverage() Dim total As Integer ' sum of grades entered by user Dim gradeCounter As Integer ' number of grades input Dim grade As Integer ' grade input by user Dim average As Integer ' average of grades Dim max As Integer Dim min As Integer ' initialization phasetotal = 0
' set total to zerogradeCounter = 1
' prepare to loop ' processing phase While gradeCounter <= 15 ' loop 15 times ' prompt for and input grade from userConsole.Write(
"Enter grade: ") ' prompt for gradegrade = Console.ReadLine()
' input the next gradetotal += grade
' add grade to totalgradeCounter += 1
' add 1 to gradeCounter If grade > max Thenmax = grade
End If End While ' termination phaseaverage = total \ 15
' integer division yields integer result ' display total and average of gradesConsole.WriteLine(vbCrLf &
"Total of all 15 grades is " & total)Console.WriteLine(
"Class average is " & average)Console.WriteLine(
"The maximum value is " & max)Console.WriteLine(
"The minimum value is " & min) End Sub ' DetermineClassAverageEnd
Class ' GradeBookI know finding the minimum should be easy but if anyone could help it would be great!

Minimum function
Jebrew
as Tada said or just set it = to the first iteration and then check for less than the first value
While gradeCounter <= 15 ' loop 15 times
' prompt for and input grade from user
Console.Write(
"Enter grade: ") ' prompt for gradegrade = Console.ReadLine()
' input the next gradetotal += grade
' add grade to total If grade > max Thenmax = grade
End IfIf (gradeCounter=0) or (grade<min) then
min = grade
End if
gradeCounter += 1 ' add 1 to gradeCounter
End WhileECHS BACHS
heavenlycharmus
Did you rearrange the code as shown....especially putting the counter incement at the end of the loop...
I did test the code and it works on this end...lets see exactly what you have
I also noticed that you start the counter with 1 and not 0...that being the case you would have to change your logic to:
If (gradeCounter=1***) or (grade<min) then
*****Change it from =0 to =1
Syed Faraz Mahmood
Use the same logic as the max variable...
If grade > max Then
max = grade
End If
If grade < min then
min = Grade
end if
MaggieChan
RMB775