/*************************************************/
// gradeAvg2.cpp
// R. A. Hillyard
// Last Modified:  09/10/2001
//
// Determine the class average with sentinel - controlled repetition
/*************************************************/

#include <iostream>
using namespace std;
int main()
  {
  int gradeSum;     //sum of all grades
  int counter;      //number of grades entered
  int grade;        //one grade
  int average;      //class average

  counter = 0;      //how many times through loop
  gradeSum = 0;     //set sum to zero before entering loop

  cout << "Enter grade, -1 to end: ";    //get first value outside the loop
  cin >> grade;

  while(grade != -1)
    {
    gradeSum += grade;
    counter++;
    cout << "Enter grade, -1 to end: ";  //get rest of values at bottom of loop
    cin >> grade;
    }//end while
		
  //compute average and print results
  average = gradeSum/counter;	
  cout << "\nClass average is: " << average;
  return 0;
  }
  
/***************Program Output***********************/  
Enter grade, -1 to end: 68
Enter grade, -1 to end: 74
Enter grade, -1 to end: 65
Enter grade, -1 to end: 88
Enter grade, -1 to end: 93
Enter grade, -1 to end: -1

Class average is: 77