Please send questions to st10@humboldt.edu .
/*--------------------------------------------------
created by smtuttle at Mon Apr 12 14:45:36 PDT 2010
--------------------------------------------------*/
#include <iostream>
#include <cmath>
using namespace std;


/*--------------------------------------------------
 Contract: avg_grades : int -> double 
 Purpose: expects the number of grades to be averaged,
         and interactively asks the user for that
         many grades, and then it produces the
         average of those grades

 Examples: for avg_grades(3),
   if you enter 100, 90, and 80 when prompted, then
   avg_grades(3) == 90.0
--------------------------------------------------*/

double avg_grades(int num_grades)
{
    /* set up needed local variables */

    double latest_grade;
    double sum_grades = 0;
    int count = 0;

    /* 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 return the average */

    if (num_grades == 0)
        return 0.0;
    else
        return sum_grades / num_grades;
}