/*************************************************/
// gradeAvg4.cpp
// R. A. Hillyard
// Last Modified:  09/10/2001
//
// Determine the class average with a do / while loop
/*************************************************/

#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

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

Class average is: 77