< previous page page_497 next page >

Page 497
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
while (response != 1 && response != 2 && response != 3)
{
    cout << Enter 1, 2, or 3: ;
    cin >> response;
}
6. Rewrite the following code segment using a While loop.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
cin >> ch;
if (cin)
    do
    {
        cout << ch;
        cin >> ch;
    } while (cin);
7. Rewrite the following code segment using a For loop.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
sum = 0;
count = 1;
while (count <= 1000)
{
    sum = sum + count;
    count++;
}
8. Rewrite the following For loop as a While loop.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
for (m = 93; m >= 5; m--)
    cout << m <<    << m * m << endl;
9. Rewrite the following For loop using a Do-While loop.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
for (k = 9; k <= 21; k++)
    cout << k <<   << 3 * k << endl;
10. Write a value-returning function that accepts two int parameters, base and component, and returns the value of base raised to the exponent power. Use a For loop in your solution.
11. Make the logic of the following loop easier to understand by using an infinite loop with break statements.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
sum = 0;
count = 1;
do
{
    cin >> int1;
    if ( !cin || int1 <= 0)
        cout << Invalid first integer.;

 
< previous page page_497 next page >