< previous page page_a53 next page >

Page A53
4. Six iterations are performed.
9. (sum contains the sum of the integers from 0 through count -1) AND (0 < count < 22)
10. Telephone numbers read in as integers have many different values that could be used as sentinels. In the United States, a standard telephone number is a positive seven-digit integer (ignoring area codes) and cannot start with 0, 1, 411, or 911. Therefore, a reasonable sentinel may be negative, greater than 9999999, or less than 2000000.
13. a. (1) Change < to <=. (2) Change 1 to 0. (3) Change 20 to 21.
b. Changes (1) and (3) make count range from 1 through 21. Change (2) makes count range from 0 through 20.
Chapter 6
Programming Warm-Up Exercises
1. dangerous = FALSE;
   while ( !dangerous )
   {
       cin >> pressure;
       if (pressure > 510.0)
           dangerous = TRUE;
   }
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
or
dangerous = FALSE;
while ( !dangerous )
{
    cin >> pressure;
    dangerous = (pressure > 510.0);
}

2. count28 = 0;
   loopCount = 1;
   while (loopCount <= 100)
   {
       inputFile >> number;
       if (number == 28)
           count28++;
       loopCount++;
}

6. positives = 0;
   negatives = 0;
   cin >> number;
   while (cin)      // While NOT EOF
   {

 
< previous page page_a53 next page >