The homework problem is to write a program that adds together all the scores from a class exam and find the average.
I have two questions. To find the average, you have to divide the total score by the number of test takers. I don’t know how to record how many test takers there are.
Does the method for getting the average go in the while loop or outside the while loop?
import acm.program.*;
public class AvgScore extends ConsoleProgram {
public void run(){
println("This program averages the test scores of an exam until the SENTINEL is entered .");
int total = 0;
while(true) {
int score = readInt("enter the test score: ");
if (score == SENTINEL) break;
total += score;
}
println("the average for the class was");
}
private static final int SENTINEL = -1;
}
just add a count variable for every read
the calculate the average