Chapter 5
Chapter 5
19
for Looping (Repetition)
Structure (continued)
21
for Looping (Repetition)
Structure (continued)
• C++ allows you to use fractional values for
loop control variables of the double type
− Results may differ
• The following is a semantic error:
• If the user enters a score less than 0 or greater than 50, the user
should be prompted to re-enter the score. The following do...while
loop can be used to accomplish this objective:
int score;
do
{
cout << "Enter a score between 0 and 50: ";
cin >> score;
cout << endl;
}
while (score < 0 || score > 50);