How do I average?. I am suppose to find the average of the GPA
, total of students, and the total of GPA
.
example:
input: 4
Just swap the order of your statements in the while loop and your code should work fine. In this case,your check (whether to add the i/p to the total) will be done after you key in. Hence,when you key in -1,the you won't enter the while loop and the last value of -1 won't be added.
while (GPA >=0) {
total = total + GPA;
GPA = keyboard.nextDouble();
count++;
}