The program will keep asking user for grades You don't know how many grades the user will enter. The program will stop when the user enters a special number-1. We call this special number a sentinel. We use it to indicate the end of user input. Don't add this number to the total. The program will then output the average grade. Sample output: a. out Please Enter a grade, enter -1 to end: 78 Please Enter a grade, enter -1 to end: 95 Please Enter a grade, enter -1 to end: 83 Please Enter a grade, enter -1 to end: 67 Please Enter a grade, enter -1 to end: 92 Please Enter a grade, enter -1 to end: -1 The class average is 83.
Explanation / Answer
#include using namespace std; int main() { int sentinel = -1; int total = 0; int n = 0; while(1) { int grade; coutgrade; if(grade==sentinel) break; total += grade; n++; } cout