In: Computer Science
We want to count how many passing grades are entered. We don’t know how many grades there will be. Use a sentinel controlled while loop that will ask the user to enter student grades until a value of -1 is entered. Use a counter variable to count all the grades that are passing grades, where 70 is the minimum passing grade. If there are any grades that are out of the range 0 – 100, present an error message to the user, and do not count that grade as passing. We also would like to see what percentage of the valid grades are passing.
Explanation:
Here is the code which keeps asking the user for the grades until the user enters a -1 for the grade.
All the valid grades are considered only, and the passing grades are counted and at last, the count is printed along with the percentage of passing grades among the valid grades entered.
Code;
#include <iostream>
using namespace std;
int main()
{
int grade;
cout<<"Enter grade: ";
cin>>grade;
int pass = 0;
int count = 0;
while(grade!=-1)
{
if(grade<0 || grade>100)
cout<<"Invalid Grade. Range should be
1-100"<<endl;
else
{
count++;
if(grade>=70)
pass++;
}
cout<<"Enter grade: ";
cin>>grade;
}
cout<<"Total number of passing grades entered:
"<<pass<<endl;
cout<<"Percentage of passing grades entered:
"<<(float)(pass*100)/(float)count;
return 0;
}
Output:

PLEASE UPVOTE IF YOU FOUND THIS HELPFUL!
PLEASE COMMENT IF YOU NEED ANY HELP!