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
1
Expert's answer
2011-05-17T11:09:29-0400
#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;
Comments
Leave a comment