Answer to Question #187343 in C++ for jay

Question #187343

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.


1
Expert's answer
2021-05-01T17:50:49-0400
#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;
}

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