I have a program that allows the user to enter a specific number of test scores. Based on these test scores, the program should display the average score and calculate how many of the scores were above 90. I have most of it done but I'm having trouble figuring out how to calculate the number of scores that were above 90. What am I doing wrong?
#include <iostream>
#include <iomanip>
usingnamespace std;
// Function prototypes
double average(double*, int);
int howManyA(double*, int);
int main()
{
// Variable declarations
double *score; // Dynamically allocate an array of test scores
double scoreAverage = 0; // Hold the average test score
int numOfA;
int numScores; // Number of test scores
int count; // Counter variable
// Get the number of tests
cout << "How many tests do you wish to process? ";
cin >> numScores;
// Verify input is not a negative number
while (numScores <= 0)
{
// Get input again.
cout << "Please enter a positive number: ";
cin >> numScores;
}
// Dynamically allocate an array large enough to hold the test scores
score = newdouble[numScores];
// Get the specified number of test scores
cout << "Enter the test scores below.\n";
for (count = 0; count < numScores; count++)
{
cout << "Test " << (count + 1) << ": ";
cin >> *(score + count);
// Verify input is not a negative number
while (*(score + count) < 0)
{
// Get input again.
cout << "Please enter a valid test score.\n";
cin >> *(score + count);
}
}
// Calculate the average test score
scoreAverage = average(score, numScores);
// Calculate the number of A grades
numOfA = howManyA(score, numScores);
// Display the results.
cout << fixed << showpoint << setprecision(2);
cout << endl;
cout << "The average of those scores is: " << scoreAverage << endl;
cout << "The number of A grades is: " << numOfA << endl;
// Free dynamically allocated memory
delete [] score;
score = 0; // Make testScores point to null
return 0;
}
//**************************************************
// Definition of function average. *
// This calculates the average of the test *
// scores that were inputted by the user. *
//**************************************************
double average(double* score, int numScores)
{
double averageOfScores;
double total = 0.0;
for (int count = 0; count < numScores; count++)
{
total += score[count];
}
averageOfScores = total / numScores;
return averageOfScores;
}
//**************************************************
// Definition of function howManyA. *
// This calculates the number of scores that *
// were above 90. *
//**************************************************
int howManyA(double* score, int numScores)
{
int A = 0;
for (int i = 0; i >= numScores; i++)
{
if (score[i] >= 90)
{
A++;
}
}
return A;
}