February 2014
Beginner
1248 pages
62h 25m
English
Line 37 declares double variable average, which allows us to store the class average as a floating-point number. Line 14 initializes gradeCounter to 0, because no grades have been entered yet. Remember that this program uses sentinel-controlled repetition to input the grades. To keep an accurate record of the number of grades entered, the program increments gradeCounter only when the user enters a valid grade.
Compare the program logic for sentinel-controlled repetition in this application with that for counter-controlled repetition in Fig. 4.8. In counter-controlled repetition, each iteration of the while statement (lines 17–23 of Fig. 4.8) reads a value from ...
Read now
Unlock full access