I have been trying to code a program that takes input from the user for scores and then calculated the average with an input validation. The only thing I am unable to figure out is how to tell the number of scores entered which are greater than 80. Also I have to do this without using arrays.
Here's what I currently have but is not working and starts the counter from 5 instead of 1 and then incrementing it as the scores greater than 80 are entered.
int main()
{
int score, sum=0, greater=0;
for(int i=1; i<=5; i++)
{
cout<<"Enter the score: "; //take user input for scores
cin>>score;
if(score>80)
{
for (int i=1; i<=5; i++){
greater= greater+1;
}
cout<<"There are "<<greater<<" number more than 80";
}
while (! (score >=0 && score <= 100 )) //input validation
{
cout << "Invalid Input. Enter the score between the range 0 - 100" << endl;
cout << "Enter the score: ";
cin >> score;
}
sum = sum + score;
}
float avg;
avg = sum/5.0; //calculating the average
cout<<"Average of scores: "<<avg<<endl;
Can anybody help me with this? It would be much appreciated. Thanks!
I tried the above listed code and also tried to tweak it but it still shows the count as multiple of 5.