Ask Question

Convert the following do-while loop to a while loop: char sure; do { cout <> sure; }while (sure! = 'Y' && sure! = 'N');

+1
Answers (1)
  1. 25 October, 09:24
    0
    char sure;

    cout << "Are you sure you want to quit? ";

    cin >> sure;

    while (sure! = 'Y' && sure! = 'N') {

    cout << "Are you sure you want to quit? ";

    cin >> sure;

    }

    Explanation:

    The loop is used in the programming for executing the part of code or statement again and again until the condition is not false.

    do-while is the loop statement but it has a special property, it prints the statement first then checks the condition.

    So, the loop executes the statement once, if the condition is false in the starting.

    In the other loops, condition checks first and then execute the statement accordingly.

    To change the do-while to while, we write the statement once outside of the loop in the starting then execute the loop and put the same statement inside the loop and it runs again until the condition true.

    After the above change, while loop works the same as do-while.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Convert the following do-while loop to a while loop: char sure; do { cout sure; }while (sure! = 'Y' && sure! = 'N'); ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers