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.
#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";
}
}
}
Comments
Leave a comment