// Function prototypes //******************************************** // Function average * // This function calculates and returns the * // average of the values stored in the array * // passed into the scores parameter. The * // parameter numScores holds the number of * // elements in the array. * //******************************************** double average(double* testScores, int numScores); double highest(double* testScores, int numScores); double lowest(double* testScores, int numScores); #include <iostream> using namespace std; int main() { double *testScores, total = 0.0; int numScores = 0; while (numScores <= 0) { cout << "How many test scores will you enter? "; cin >> numScores; if (numScores <= 0) { cout << "The number of test scores cannot be negative or 0. " << endl; } } testScores = new double[numScores]; for (int count = 1; count <= numScores; count++) { cout << "Enter test score " << count << ": "; cin >> testScores[count]; } cout << "Average score: " << average(testScores, numScores); system("pause"); return 0; } double average(double* testScores, int numScores) { double sum = 0, average; for (int count = 0; count < numScores; count++) { sum = (sum + testScores[count]); } average = (sum / numScores); return average; }

And here is the output:

Quote

How many test scores will you enter? 3

Enter test score 1: 90

Enter test score 2: 85

Enter test score 3: 75

Average score: -2.09248e+066Press any key to continue . . .

Enter test score 1: 90

Enter test score 2: 85

Enter test score 3: 75

Average score: -2.09248e+066Press any key to continue . . .