-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimpleCalculator.cpp
More file actions
88 lines (72 loc) · 2.59 KB
/
simpleCalculator.cpp
File metadata and controls
88 lines (72 loc) · 2.59 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <iostream>
using namespace std;
int main()
{
cout << "\n\t\t-----------------------------------------------------" << endl
<< "\t\t#####################################################" << endl
<< "\n\t\t\t\t C A L C U L A T O R" << endl
<< "\n\t\t#####################################################" << endl
<< "\t\t-----------------------------------------------------" << endl
<< endl;
while (true)
{
cout << "\nEnter 1st Number: ";
float n1;
cin >> n1;
cout << "Enter 2nd Number: ";
float n2;
cin >> n2;
cout << "\nOperations:\n"
"\n"
" \tENTER "
<< "1" << " to ADD "
" \tENTER "
<< "2" << " to SUBTRACT\n"
" \tENTER "
<< "3" << " to MULTIPLY"
" \tENTER "
<< "4" << " to DIVIDE\n"
" \tENTER "
<< "0" << " to OFF\n"
"\n"
"Enter your Operation: ";
float operation;
cin >> operation;
if (operation == 1)
{
cout << "----------------------------" << endl
<< "\t" << n1 << " + " << n2 << " = " << n1 + n2 << endl
<< "----------------------------" << endl;
}
else if (operation == 2)
{
cout << "----------------------------" << endl
<< "\t" << n1 << " - " << n2 << " = " << n1 - n2 << endl
<< "----------------------------" << endl;
}
else if (operation == 3)
{
cout << "--------------------------------" << endl
<< "\t" << n1 << " * " << n2 << " = " << n1 * n2 << endl
<< "--------------------------------" << endl;
}
else if (operation == 4)
{
if (n2 != 0)
cout << "---------------------------------" << endl
<< "\t" << n1 << " / " << n2 << " = " << n1 / n2 << endl
<< "---------------------------------" << endl;
else
cout << "Division by 0 is not allowed " << endl;
}
else if (operation == 0)
{
cout << " SWITCHING OFF " << endl
<< "--------------------------------" << endl;
exit(0);
}
else
cout << " INVALID OPERATION:" << endl;
}
return 0;
}