... user types the end-of-file indicator.
Line 25 inputs a grade value from the user. Line 26 adds grade to total. Line 27 increments gradeCounter. These variables are used to compute the average of the grades. Lines 30–47 use a switch statement to increment the appropriate letter-grade counter based on the numeric grade entered.
Processing the Grades
The switch statement (lines 30–47) determines which counter to increment. We assume that the user enters a valid grade in the range 0–100. A grade in the range 90–100 represents A, 80–89 represents B, 70–79 represents C, 60–69 represents D and 0–59 represents F. The switch statement consists of a block that contains a sequence of case labels and an optional default case. These are used in this example ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access