Ask Question
9 November, 11:23

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.

+4
Answers (1)
  1. 9 November, 12:10
    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?
Find 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 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