// Ch. 14 Demo Program #3
// Mr. Minich
// Purpose - to illustrate the use of parallel apvectors

#include <iostream.h>
#include "M:\C++ Programming\AP classes\apvector.h" int main() { int runningTotal = 0; int count = 0; apvector <int> goodGames(101, 0); apvector <int> gameScores(101, 0); // goodGames and gameScores are used as parallel arrays (or vectors) do { count++; // not using zero position cout << "Enter the score of Game " << count << " (-99 to stop): "; cin >> gameScores[count]; if (gameScores[count] != -99) { runningTotal = runningTotal + gameScores[count]; } if (gameScores[count] >= 200) { goodGames[count] = 1; } } 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 << endl; cout << "You bowled 200 or better in the following games: "; for (int i = 0; i <= count; i++) // count was decremented above { // and now reflects the correct // number of games. if (goodGames[i] == 1) { cout << i << " "; }
} cout << endl; return 0; }// end of main