Hello, i was required to make a program that will prompt the user to input 10 numbers and put it into an array and then calculate the average. It also needs to report how many numbers in the array that are larger than the average.
Everything is successful except the latter part. I don't know what is wrong with my for loop statement that will determine how many members of the array are larger than the average. I tried everything, all i get is 0 and 10.
constint donation = 10;
cout << endl << endl;
cout << "Instructions: Please input 10 numeric number, the program\n"
<< "will calculate its average and determine what number is higher\n"
<< "than the average.\n\n";
double* donationArr = newdouble [donation]; // Dynamic array of 10 double
int arrayCount = 0;
cout << "Input number #1: ";
while (arrayCount < donation && cin >> donationArr[arrayCount]) // Continue looping if the input didnt fail and the arrayCount is less than the donation.
{ // Also this will put number in the arrayCount.
if (++arrayCount < donation) // execute the statement below if true
cout << "Input number #" << arrayCount+1 << ": ";
}
double averageAns = 0.0;
int arrayHigher = 0;
// Calculate the number inside the array
for (int counter = 0; counter < donation; ++counter)
averageAns += donationArr[counter];
// Count the number that is higher than the average
for (int counter = 0; counter < donation; ++counter)
if (averageAns < donationArr[counter])
++arrayHigher;
// Show result
if (arrayCount == 0)
cout << "\n\nNo input! The program is terminated.\a\a\n\n";
else
{
cout << "\n\nTotal: " << averageAns << endl;
cout << "\n\nAverage: " << averageAns / donation << endl;
cout << "Number higher than average = " <<arrayHigher << endl << endl;
}
delete [] donationArr; // Freeing the dynamic array of 10 double
return 0;
}