Problem

We could have written the loop to manage the interaction with the user as a do while (§ 5....

We could have written the loop to manage the interaction with the user as a do while (§ 5.4.4, p. 189) loop. Rewrite the loop to use a do while. Explain which version you prefer and why.

§ 5.4.4 (p. 189)

Exercise 5.18

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);

Exercise 5.19

Write a program that uses a do while loop to repetitively request two strings from the user and report which string is less than the other.

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 12
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT