-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2-0-2-4.cpp
More file actions
41 lines (35 loc) · 744 Bytes
/
2-0-2-4.cpp
File metadata and controls
41 lines (35 loc) · 744 Bytes
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
32
33
34
35
36
37
38
39
40
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
int data1, data2;
char op;
cin >> data1 >> data2 >> op;
switch (op) {
case '+':
cout << data1 + data2 << endl;
break;
case '-':
cout << data1 - data2 << endl;
break;
case '*':
cout << data1 *data2 << endl;
break;
case '/':
if (data2 == 0) {
cout << "error" << endl;
} else {
double result = static_cast<double>(data1) / data2;
if (data1 % data2 == 0) {
cout << fixed << setprecision(0) << result << endl;
} else {
cout << fixed << setprecision(2) << result << endl;
}
}
break;
default:
cout << "Invalid operator" << endl;
break;
}
return 0;
}