Basically I have burned out my brain doing 4 other problems just fine and I have no idea what so ever how to begin or even do this problem.
Write a function that reads in 10 grades and determines how many are above or equal to the average and how many are below. Read in the grades in main(), call the function to do the calculation, and print out the entire array so you can verify the result. in C++
// declare variables
array or vector to store grades
total grade
average grade
count of how many are above or equal to average
count of how many are below average
// input
ask user to input 10 grades and store it in array // you can use a for/while loop
in that loop add the grade to the total // compound operator (+=)
// calculate the average
average = total / 10
use a loop to filter thru the array
if grade is greater than or equal to average
increment count of above or equal to average
else
increment count of below average
while you're looping through the array
you may as well print it out
#include <iostream>
#include <iomanip>
usingnamespace std;
double get_average(double *scores, constint iElements)
{
double total = 0.0;
//Calculate the total of the scores
for (int count = 0; count < iElements; count++) {
total += scores[count];
}
return total / iElements;
}
int get_geavg(double *scores, constint& iElements, double& dblAvg)
{
int ge = 0;
for (int i = 0; i < iElements; i++) {
if (scores[i] >= dblAvg) ++ge;
}
return ge;
}
int main ()
{
double *scores, //To dynamically allocate an array
total = 0.0,
average;
int numScores,
count,
greater = 0, // number of results greater or equal average
less = 0; // number of results less than average
//Get the number of test scores
cout << "How many test scores would you like to enter? ";
cin >> numScores;
//Dynamically allocate an array large enough to hold that many test scores
scores = newdouble[numScores];
//Get the test scores
cout << "Enter the test scores below.\n";
for (count = 0; count < numScores; count++)
{
cout << "Test Score " << (count + 1) << ": ";
cin >> scores[count];
}
average = get_average(scores, numScores);
int above_average = get_geavg(scores, numScores, average);
//Display the results
cout << fixed << showpoint << setprecision(2);
cout << " Average score is: " << average << endl;
cout << "Above Average scores: " << above_average << endl;
cout << "Below Average scores: " << numScores - above_average << endl;
//Free dynamically allocated memory
delete [] scores;
return 0;
}