Please send questions to
st10@humboldt.edu .
/*-----
Contract: main: void -> int
Purpose: interactively ask the user for 5 grades, and
average them, printing the averaged result
to the screen
Examples: when called, if the user types in
100, 90, 80, 87, 92.5 when
prompted, then it will print to the screen:
The average of those 5 grades is: 89.9
by: Sharon M. Tuttle
last modified: 4-11-10
-----*/
#include <iostream>
using namespace std;
int main()
{
/* set up the needed local variables and constant */
double latest_grade;
double sum_grades = 0;
int count = 0;
const int NUM_GRADES = 5;
/* read in and add up the grades */
while (count < NUM_GRADES)
{
cout << "Please enter a grade: ";
cin>> latest_grade;
sum_grades = sum_grades + latest_grade;
count++;
}
/* compute and output the average */
cout << "The average of the " << NUM_GRADES
<< " grades is: " << sum_grades / NUM_GRADES
<< endl;
return EXIT_SUCCESS;
}