I am new to c++ and am in my first class..we are currently working on the do-while statement and i am stuck. Here is the exercise:
Write, compile, and run a C++ program that continuously requests a grade to be entered. If the grade is less than 0 or greater than 100, your program should print a message informing the user that an invalid grade has been entered; else, the grade should be added to a total. When a grade of 999 is entered, the program should exit the repetition loop and compute and display the average of the valid grades entered.This is what i've got so far....
#include <iostream>
using namespace std;
int main ()
{
int grade;
do {
cout << "Enter a grade : ";
cin >> grade;
} while (grade > 0 || grade <100);
else
cout >> "The grade just entered is invalid";
system("pause");
return 0;
}
I am confused about the part of the program that says:
"else, the grade should be added to a total. When a grade of 999 is entered, the program should exit the repetition loop and compute and display the average of the valid grades entered."
#include <iostream>
usingnamespace std;
int main()
{
//Declare Variables
int grade = 0;
double total = 0.0;
int numberOfGrades = 0;
double average = 0.0;
do //begin loop
{
cout << "Enter a grade. (Enter 999 to quit.): ";
cin >> grade;
if (grade < 0 || grade > 100)
cout << "The grade you entered is invalid" << endl;
else
{
numberOfGrades += 1;
total = total + grade;
} //end if
} while (grade != 999); //end loop
average = total / numberOfGrades;
cout << endl << endl;
cout << "The average of the grades entered is " << average << endl;
system("pause");
return 0;
} //end of main function