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.
#include <iostream>
using namespace std;
int main()
{
float n1, n2, product;
char answer;
cout<<"Please enter two numbers separated by a space:\n";
cin >> n1 >> n2;
product = n1*n2;
cout << "Their product is: "<< product << "\n";
cout<< "Do you want to enter another pair of numbers? [y/n]\n";
cin>>answer;
while(answer=='y'){
cout<<"Please enter two numbers separated by a space:\n";
cin >> n1 >> n2;
product = n1*n2;
cout << "Their product is: "<< product << "\n";
cout<< "Do you want to enter another pair of numbers? [y/n]\n";
cin>>answer;
}
return 0;
}
Comments
Leave a comment