-
Notifications
You must be signed in to change notification settings - Fork 0
/
calculator_2.cpp
56 lines (47 loc) · 1.19 KB
/
calculator_2.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
53
54
55
56
#include <iostream>
using namespace std;
// Calculator using if and else conditions!
int main()
{
while (true)
{
double num1, num2, result;
char op;
cout<<endl;
cout<<"Enter your 1st Number: "<<endl;
cin>>num1;
cout<<"Choose Operator: +, -, *, /"<<endl;
cin>>op;
cout<<"Enter your 2nd Number: "<<endl;
cin>>num2;
if (op == '+')
{
result = num1 + num2;
cout<<"Your answer is: "<<result<<endl;
}
else if (op == '-')
{
result = num1 - num2;
cout<<"Your answer is: "<<result<<endl;
}
else if (op == '*')
{
result = num1 * num2;
cout<<"Your answer is: "<<result<<endl;
}
else if (op == '/')
{
if (num2 == 0)
{
cout<<"Division with 0 is not allowed!"<<endl;
}
else{
result = num1 / num2;
cout<<"Your answer is: "<<result<<endl;
}
}
else{
cout<<"Result was not possible due to Invalid Operator!"<<endl;
}
}
}