New to Java and would appreciate the help with the assignment: Write a program to collect exam grades from keyboard until an invalid grade (grade less than 0 or bigger than 100) inputted. Find how many grades were entered, the corresponding average grade, how many grades above 90, and how many grades lower than 60
-I am able to input the first two number and then recieve an error.
Could someone please simply explain why this does not work properly? Thank you!
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int grades;
int avg=0;
int totalCount=0;
int agrades=0;
int fgrades=0;
Scanner input = new Scanner(System.in);
System.out.println("Enter Grades: ");
grades = input.nextInt();
boolean numbers = true;
while (numbers){
grades = input.nextInt();
if (grades < 0 || grades > 100)
numbers = false;
avg = grades + grades/totalCount;
totalCount++;
if (grades >= 90)
agrades++;
if (60 >= grades)
fgrades++;
System.out.println("Enter Grades: ");
grades = input.nextInt();
}
System.out.println("Amount of Grade: " + totalCount);
System.out.println("Averaage Grade: " + avg);
System.out.println("Number of grades above 90: " + agrades);
System.out.println("Number of grades below 60: " + fgrades);
}
}