// Mr. Minich
// CMPSC 101
// Ch. 10 Demo Program #2
// January 30, 2000
// Purpose - the use of a sentinel value and summing all elements of an array
#include <iostream>
using namespace std;
int main()
{
int runningTotal = 0; // total of all scores so far
int count = 0; // position within array
int gameScores[100]; // it is assumed that the user
// will not need to enter more
// than 100 game scores
do
{
count++; // we are not going to make use of the
// zero position of the array
cout << "Enter the score of Game " << count << " (-99 to stop): ";
cin >> gameScores[count];
if (gameScores[count] != -99)
{
runningTotal = runningTotal + gameScores[count];
}
} while(gameScores[count] != -99);
// runningTotal is an accumulator.
// The user enters the sentinel value of -99 to indicate that he/she
// is finished entering game scores.
cout << "Your average score was " << runningTotal / (count - 1) << endl;
return 0;
}// end of main