76 255
Assignments Done
Successfully Done
In May 2019

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;

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

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

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!


No comments. Be first!

Leave a comment

Ask Your question

Privacy policy Terms and Conditions