-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUntitled4.cpp
More file actions
35 lines (32 loc) · 820 Bytes
/
Untitled4.cpp
File metadata and controls
35 lines (32 loc) · 820 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
#include <iostream>
using namespace std;
void calc() {
int a, b, op;
cout << "Enter two numbers: ";
cin >> a >> b;
cout << "Enter operation (1=add, 2=sub, 3=mul, 4=div): ";
cin >> op;
switch(op) {
case 1:
cout << "Result is " << a + b << endl;
break;
case 2:
cout << "Result is " << a - b << endl;
break;
case 3:
cout << "Result is " << a * b << endl;
break;
case 4:
if (b != 0)
cout << "Result is " << a / b << endl;
else
cout << "Error: Division by zero" << endl;
break;
default:
cout << "Invalid operation" << endl;
}
}
int main() {
calc();
return 0;
}