i am coding a program to let the user enter unspecified numbers of score until the user enter a negative number,the program will display the average of the scores and the number of scores which are above or equal to the average, and also the number of scores which are below the average.
i'm almost done.
but at last i can't find the number of scores which are above or equal to the average, and also the number of scores which are below the average.
Please help this is the last step ;(
#include <iostream>
#include <iomanip>
#include <cmath>
usingnamespace std;
int main ()
{
constint NUM_SCORE = 100 ;
int scores[NUM_SCORE];
int count;
int sum=0;
double average;
for(count=0;count < NUM_SCORE;count++)
{
cout << "Enter score " << (count + 1) << ": ";
cin >> scores[count];
sum += scores[count];
if(scores[count]<0)
{break;}
}
int high=0;
int low=0;
average = sum/(count);
for(count = 0;count <= NUM_SCORE;count++)
{
if(scores[count]>=average)
{high++;}
else
{low++;}
}
cout << "The average of the scores is: " << fixed << setprecision(2) << average+1 << endl;
cout << "The number of score(s) that are above or equal to the average: " << high << endl;
cout << "The number of score(s) that are below the average: " << low << endl;
return 0;
}
I’m very new to programming but, I fidgeted w/your code for a while and came to a conclusion I believe you were trying to reach. I did alter you code quite a bit but, hopefully the solution is helpful. I’m almost certain there are better / less altered solutions out there that I would also be interested in seeing.
#include <iostream>
usingnamespace std;
int main () {
cout << "Enter number of games followed: ";
int NUM_SCORE;
cin >> NUM_SCORE;
int *scores;
scores = newint [NUM_SCORE];
int count;
double sum=0;
double average;
for(count=0;count < NUM_SCORE;count++)
{
cout << "Enter score " << (count+1) << ": ";
cin >> scores[count];
sum += scores[count];
}
int high =0;
int low =0;
average = sum/(NUM_SCORE);
for (count =0; count < NUM_SCORE; count++) {
if (scores [count] >=average)
{high++;}
else
{low++;}
}
cout << "The average of the scores is: " << average << endl;
cout << "The number of score(s) that are above or equal to the average: " << high << endl;
cout << "The number of score(s) that are below the average: " << low << endl;
delete [] scores;
return 0;
}