60 430
Assignments Done
98,1%
Successfully Done
In April 2018

Answer to Question #26294 in C++ for red rose

Question #26294
Write a program that accepts two real numbers from a user and a select code. If the entered select code is 1, have the program add the two previously entered numbers and display the result; if the select code is 2, the numbers should be multiplied, and if the select code is 3, the first number should be divided by the second number. Division by 0 is not allowed and an appropriate message is displayed when such a division is attempted.

Expert's answer
#include <iostream>

using namespace std;

int main()
{
/* Asks the user to enter 2 numbers */
double a, b;
cout << "Enter two real numbers: ";
cin >> a >> b;

/* Prompt for a select code */
int selectCode;
cout << "Enter a select code: ";
cin >> selectCode;

/* Perform an arithmetic operation according to the select code */
switch (selectCode)
{
case 1:
cout << "The sum is " << a + b << endl;
break;

case 2:
cout << "The product is " << a * b << endl;
break;

case 3:
if (b == 0)
cout << "Division by zero is not allowed" << endl;
else
cout << "The quotient is " << a / b << endl;
break;

default:
cout << "Wrong select command" << endl;
}
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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions