... precision)
35 cout << "\nTotal of the " << gradeCounter
36 << " grades entered is " << total;
37 cout << setprecision(2) << fixed;
38 cout << "\nClass average is " << average << endl;
39 }
40 else { // no grades were entered, so output appropriate message
41 cout << "No grades were entered" << endl;
42 }
43 }
Enter grade or -1 to quit: 97 Enter grade or -1 to quit: 88 Enter grade or -1 to quit: 72 Enter grade or -1 to quit: -1 Total of the 3 grades entered is 257 Class average is 85.67
Recall that integer division produces an integer result. This program introduces a special operator called a cast operator to force the averaging calculation to produce a floatingpoint numeric result. This program also stacks control statements on top of one another ...
Get C++ How to Program, 10/e now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.