-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculator.cpp
52 lines (45 loc) · 1.02 KB
/
calculator.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <iostream>
using namespace std;
int main(){
cout << "Menu \n";
string operations[5] = { "Add", "Subtract", "Multiply", "Divide","Modulus" };
int result, num1, num2;
int choice = 0;
string operation;
int size = (sizeof(operations)/sizeof(*operations));
for( int i =0; i <= size-1; i++){
cout << i+1 << ". " << operations[i] << endl;
}
cout << "Enter your operation choice : " ;
cin >> choice;
cout << "Enter the First number : ";
cin >> num1;
cout << "Enter the second number : ";
cin >> num2;
switch(choice){
case(1):
operation = "+";
result = num1 + num2;
break;
case(2):
operation = "-";
result = num1 - num2;
break;
case(3):
operation = "*";
result = num1 * num2;
break;
case(4):
operation = "/";
result = num1 / num2;
break;
case(5):
operation = "%";
result = num1 % num2;
break;
default:
cout << "Invalild operand";
}
cout << num1 << operation << num2 << " = " <<result;
return 0;
}