-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculator.cpp
More file actions
102 lines (82 loc) · 3.03 KB
/
Calculator.cpp
File metadata and controls
102 lines (82 loc) · 3.03 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include <iostream>
#include <windows.h>
#include <iomanip>
using namespace std;
// Function to change text color
void color(int col) {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), col);
}
// Loading animation
void loading() {
color(14);
cout << "\n\n Loading Calculator";
for(int i = 0; i < 5; i++) {
cout << ".";
Sleep(300);
}
cout << "\n\n";
}
int main() {
double a, b, result;
char op, again;
system("cls");
loading();
do {
system("cls");
color(11);
cout << "\n===============================================\n";
cout << " ? CALCULATOR APP ? \n";
cout << "===============================================\n\n";
color(14);
cout << " Available Operations:\n\n";
color(10); cout << " [+] Addition\n";
color(12); cout << " [-] Subtraction\n";
color(13); cout << " [*] Multiplication\n";
color(9); cout << " [/] Division\n\n";
color(15);
cout << "-----------------------------------------------\n";
cout << " Enter First Number : ";
cin >> a;
cout << " Enter Second Number : ";
cin >> b;
cout << " Choose Operation (+, -, *, /): ";
cin >> op;
cout << "-----------------------------------------------\n";
color(11);
switch(op) {
case '+': result = a + b;
cout << " Result: " << a << " + " << b << " = " << result << endl;
break;
case '-': result = a - b;
cout << " Result: " << a << " - " << b << " = " << result << endl;
break;
case '*': result = a * b;
cout << " Result: " << a << " * " << b << " = " << result << endl;
break;
case '/': if(b != 0) {
cout << fixed << setprecision(2);
result = a / b;
cout << " Result: " << a << " / " << b << " = " << result << endl;
} else {
color(12);
cout << " ? ERROR: Division by Zero Not Allowed!\n";
}
break;
default:
color(12);
cout << " ? Invalid Operation Selected.\n";
}
color(15);
cout << "-----------------------------------------------\n";
cout << " Do you want to Perform Another Calculation? (y/n): ";
cin >> again;
} while(again == 'y' || again == 'Y');
color(10);
cout << "\n===============================================\n";
cout << " ? THANK YOU FOR USING THE APPLICATION\n";
cout << " Created By: ** Khushi Chauhan **\n";
cout << " (Intern Project)\n";
cout << "===============================================\n\n";
color(7);
return 0;
}