/**
 * GradeAveragerBreak.java
 *
 * Uses a while loop to read in a series of grades from the user, 
 * and prints out their average.  It continues reading values until the user
 * enters the sentinel value of -1.
 *
 * This version of the program uses a break statement to end the loop
 * once the sentinel is read.
 *
 * Computer Science S-111
 */

import java.util.*;

public class GradeAveragerBreak {
    public static void main(String[] args) {
	Scanner console = new Scanner(System.in);
	int total = 0;
	int numGrades = 0;

	while (true) {
	    System.out.print("Enter a grade (or -1 to quit): ");
	    int grade = console.nextInt();
	    if (grade == -1) {        // sentinel value, so break out of loop
		break;
	    }
	    total += grade;
	    numGrades++;
	}

	if (numGrades > 0) {
	    System.out.println("\nThe average is ");
	    System.out.println((double)total / numGrades);
	}
    }
}
