-
Notifications
You must be signed in to change notification settings - Fork 4
/
exec4-5.cpp
31 lines (29 loc) · 942 Bytes
/
exec4-5.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>
using namespace std;
// very simple calculator
int main() {
double x = 0, y = 0;
char op;
cout << "Please enter two floating-point numbers and an operator (+ - * /)\n";
cin >> x >> y >> op;
switch (op) {
case '+':
cout << "The sum of " << x << " and " << y << " is " << x + y << endl;
break;
case '-':
cout << "The difference between " << x << " and " << y << " is " << x - y << endl;
break;
case '*':
cout << "The product of " << x << " and " << y << " is " << x * y << endl;
break;
case '/':
if (y == 0)
cout << "error: divided by 0\n";
else
cout << "The quotient of " << x << " and " << y << " is " << x / y << endl;
break;
default:
cout << "error: invalid operator " << op << endl;
}
return 0;
}