Ask Question
25 September, 07:38

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

+4
Answers (1)
  1. 25 September, 08:29
    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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers