Ask Question
20 February, 13:03

2. Design a Do-While loop that asks the user to enter two numbers. The numbers should be added and the sum displayed. The loop should ask the user whether he or she wishes to perform the operation again. If so, the loop should repeat; otherwise it should terminate.

+3
Answers (1)
  1. 20 February, 13:46
    0
    Program:

    #include / / Header file.

    using namespace std;

    int main () / / Main function which starts the executions

    {

    int First_Number, Second_Number; / / variable declaration.

    char choice; / / Variable declaration.

    do / / do while loop

    {

    cout<<"Enter two number for addition"; / / user instruction

    cin>>First_Number>>Second_Number; / / take a input

    cout<<"The adition of "<
    cout<<"/nType / "Y/" for continue the operation again otherwise press any key"; / / User message for choice.

    cin>>choice; / / input for choice.

    }

    while (choice=='Y'||choice=='y'); / / condition for Do-While loop

    return 0; / / return statement.

    }

    Output:

    If the user input are 4,5 and u then the output is 9 If the user input are 5,6 and y and 7,8 and u then the output are 11, 15.

    Explanation:

    The above code is in C+ + language. The above program firstly renders a message to enter the two numbers. Then it performs addition operation and then the result will be printed. Then it renders a message for the user choice. If the user enters capital y or small y, then the above operation will continue again. Otherwise, the program will be terminated.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “2. Design a Do-While loop that asks the user to enter two numbers. The numbers should be added and the sum displayed. The loop should ask ...” 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