Ask Question
17 October, 15:26

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

+2
Answers (1)
  1. 17 October, 18:17
    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?
Get 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 there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers