Q:

Explain each of the following loops. Correct any problems you detect

0

Explain each of the following loops. Correct any problems you detect.

(a)

do
 int v1, v2; cout << "Please enter two numbers to sum:" ; if (cin >> v1 >> v2) cout << "Sum is: " << v1 + v2 << endl;
while (cin);

(b)

do {
 // . . .
} while (int ival = get_response());

(c)

do {
 int ival = get_response();
} while (ival);

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

(a)

    //do  // Need a block here.
    do {
      int v1, v2;
      cout << "Please enter two numbers to sum:" ;
      if (cin >> v1 >> v2)
      cout << "Sum is: " << v1 + v2 << endl;
    //while (cin);
    } while (cin);

(b)

    int ival;
    do {
      // ...
    //} while (int ival = get_response());  // Error: declaration in a do condition
    } while (ival = get_response());

(c)

    int ival;
    do {
      //int ival = get_response();  // Loop will define a new condition variable everytime
      ival = get_response();
    } while (ival);

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now