Write program that allows user to enter two numeric values. Then let user enter a single character as desired operation: 'a' for add, 's' for subtract, 'm' for multiply, or 'd' for divide. perform arithmetic operationn that the user selects and display the results
#include <iostream>
using namespace std;
int main()
{
& double a, b;
& char op;
& cout << "Enter two values a and b\n";
& cout << "a = ";
& cin >> a;
& cout << "b = ";
& cin >> b;
& cout << "Enter the letter for operation\n"
& lt;< " 'a' - add: a+b\n"
& lt;< " 's' - substract: a-b \n"
& lt;< " 'm' - multiply a*b\n"
& lt;< " 'd' - divide a/b\n";
& cin >> op;
& switch (op)
& {
& case 'a':& cout << " a + b = " << a+b;
break;
& case 's':& cout << " a - b = " << a-b;
break;
& case 'm':& cout << " a * b = " << a*b;
break;
& case 'd':& cout << " a / b = " << a/b;
break;
& default: cout << "Incorrect letter for operation";
& };
& cout << 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!
Learn more about our help with Assignments:
C++