Answer to Question #187326 in C++ for jay

Question #187326

Write a program to accept two numbers at a time from the user. The product of the numbers is to be calculated and displayed. The user should then be prompted to indicate if they want to enter another pair of numbers. As long as they enter ‘y’ at the prompt they should be allowed to enter another pair of numbers. Any other entry from the user at the prompt will result in them not being able to enter any more numbers.


1
Expert's answer
2021-04-29T18:59:23-0400
#include <iostream>

using namespace std;

int main()
{
    while (true)
    {
        string answ;
        int fir, sec;
        cout << "Enter the first number: ";
        cin >> fir;
        cout << "Enter the second number: ";
        cin >> sec;
        cout << fir << " × " << sec << " = " << fir * sec;
        cout << "\nDo you want to multiply one more pair of numbers? (Y/N) ";
        cin.ignore(32767, '\n');
        getline(cin, answ);
        if (answ == "N" || answ == "n")
        {
            exit(0);
        }
        else if (answ != "Y" && answ != "y")
        {
            throw "FCK U";
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS