-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimple_Calculator.cpp
More file actions
43 lines (39 loc) · 924 Bytes
/
Copy pathSimple_Calculator.cpp
File metadata and controls
43 lines (39 loc) · 924 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
41
42
43
# include <iostream>
using namespace std ;
int main () {
// using as variab to save values
double num1;
double num2;
char op;
// using to tell user to give input
cout << "Enter First Number= " ;
cin >> num1 ;
cout << "Enter Second Number= " ;
cin >> num2 ;
cout << "Enter An Operator (+,-,/,*)= ";
cin >> op;
// using swith to run code as per conditions
switch (op)
{
case '+':
cout << "Result= " << num1 + num2 << endl;
break;
case '-':
cout << "Result= " << num1 - num2 << endl;
break;
case '*':
cout << "Result= " << num1 * num2 << endl;
break;
case '/':
if (num2 == 0){
cout << "Error: Divison With Zero Is Not Allowed";
}
else {
cout << "Result: " << num1/num2 << endl ;
}
break;
default: cout << "Error: Invalid Operator Entered" << endl;
break;
}
return 0;
}