Define a getMean() function with the specification and prototype shown below:
// Return the sum of all scores divided by the number of scores.
// This know as the "mean" or average of the scores.
// Assume that numScores > 0.
double getMean(double scores[], int numScores);
Here is the driver (main()) used to test my function:
#include <iostream>
#include <iomanip>
using namespace std;
const int MAX_SCORES = 10; // Maximum number of scores
double getMean(double scores[], int numScores);
int main() {
double scores[MAX_SCORES];
int scoreCount;
cin>>scoreCount;
scoreCount = min(MAX_SCORES, scoreCount);
for (int i = 0; i < scoreCount; i++)
cin >> scores[i];
cout << fixed <<setprecision(2);
cout <<getMean(scores, scoreCount) << endl;
return 0;
}
Here is my solution:
double getMean(double scores[], int numScores)
{
int sum;
int j;
for (j = 0; j > scores[numScores]; j++)
{
sum = (scores[j+numScores]) / numScores;
}
return(scores[sum]);
}
Here are the expected outputs I want to get:
Input: 1 1
Mean: 1
Input: 87 87 89
Mean: 87.67
Input: 70 70
Mean: 70.00
My program is supposed to calculate the mean of the scores, but it is not giving the correct output. What am I doing wrong? Did I do the calculation incorrectly?