-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathatmV1.cpp
280 lines (239 loc) · 9.51 KB
/
atmV1.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
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
/*
* This is version 1 of the C++ ATM
* Features: - Welcome and Login Screen
- 3 Users
- Balance Inquiry, Money withdrawal
- Credit transfer, Money deposit
- Touch N Go reload, Clear screen
* Developed by: Keith L
*/
#include <iostream>
#include <string>
#include <windows.h>
using namespace std;
//declare all the variables here
int safety_pin, option, recepient, acc_num;
float acc_balance, withdraw, transfer, deposit, reload;
string name;
//for the users;
int safety_pin1 = 1971;
string name1 = "Yi Long Mask";
int acc_num1 = 2203837;
float acc_balance1 = 20000.00;
int safety_pin2 = 6969;
string name2 = "Zhong Xina";
int acc_num2 = 80085;
float acc_balance2 = 420420.00;
int safety_pin3 = 111;
string name3 = "Bing Chilling";
int acc_num3 = 444;
float acc_balance3 = 111111.00;
void login() //login menu
{
cout<<"Please enter your safety pin: ";
while(!(cin >> safety_pin)) //filter out chars
{
cout <<"This is not integers! Try again!\n";
cout<<"Enter pin: ";
cin.clear();
cin.ignore(123,'\n');
}
if (safety_pin != safety_pin1 and safety_pin != safety_pin2 and safety_pin != safety_pin3)
{
do
{
system("color 0c"); //change the terminal color to red, because it looks cool
cout<<"\a";
cout<<"Wrong pin. Try again!\n";
cout<<"Enter pin: ";
while(!(cin >> safety_pin)) //filter out chars further, trust me, there was a bug here
{
cout <<"This is not integers! Try again!\n";
cout<<"Enter pin: ";
cin.clear();
cin.ignore(123,'\n');
}
}while(safety_pin != safety_pin1 and safety_pin != safety_pin2 and safety_pin != safety_pin3);
}
}
void showMenu() //main menu
{
cout<<"\n-~-~-~-~-~-~-~-~-~-~-~-~-~-~-\n"
<<"Choose what to do:\n"
<<" [1] - Balance Inquiry\n"
<<" [2] - Money Withdrawal\n"
<<" [3] - Credit Transfer\n"
<<" [4] - Money Deposit\n"
<<" [5] - Touch N Go reload\n"
<<" [6] - Clear screen\n"
<<" [0] - Quit Program\n"
<<"-~-~-~-~-~-~-~-~-~-~-~-~-~-~-\n";;
}
void action() //the looping action of atm
{
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
do
{
showMenu();
while(!(cin >> option)) //filter out chars
{
cout <<"This is not integers! Try again!\n";
cout<<"Choose what to do:\n";
cin.clear();
cin.ignore(123,'\n');
}
switch(option)
{
case 1: //account inquiry
system("cls");
cout<<"Balance Inquiry:\n"
<<"Your name: "<<name
<<"\nAccount number: "<<acc_num
<<"\nAccount balance: RM "<<acc_balance<<endl;
break;
case 2: //withdraw money
cout<<"Withdraw:\n"
<<"Account balance: RM "<<acc_balance
<<"\nWithdraw amount: RM ";
while(!(cin >> withdraw)) //filter out chars
{
cout <<"This is not integers! Try again!\n";
cin.clear();
cin.ignore(123,'\n');
cout << "\nWithdraw amount: RM ";
}
if (withdraw <= acc_balance)
{
acc_balance = acc_balance - withdraw;
cout<<"\nMoney withdrawal success. The money has been deducted from your account."
<<"\nYour current account balance is: RM "<<acc_balance<<endl;
if (acc_balance == 0)
{
cout<<"You have no money now!!";
}
}
else{
cout<<"The withdrawal amount is too much! Not enough in account balance!";
}
break;
case 3: //transfer credit
cout<<"Transfer:\n"
<<"Account balance: RM "<<acc_balance
<<"\nTransfer amount: RM ";
while(!(cin >> transfer)) //filter out chars
{
cout <<"This is not integers! Try again!\n";
cin.clear();
cin.ignore(123,'\n');
cout << "\nTransfer amount: RM ";
}
if (transfer <= acc_balance)
{
acc_balance = acc_balance - transfer;
cout<<"Transfer to (Enter recipient account number):";
cin>>recepient;
cout<<"\nMoney transfer success. The money has been deducted from your account."
<<"\nYour current account balance is: RM "<<acc_balance<<endl;
if (acc_balance == 0)
{
cout<<"You have no money now!!";
}
}
else{
cout<<"The transfer amount is too much! Not enough in account balance!";
}
break;
case 4: //deposit
cout<<"Deposit:\n"
<<"Account balance: RM "<<acc_balance
<<"\nDeposit amount: RM ";
while(!(cin >> deposit)) //filter out chars
{
cout <<"This is not integers! Try again!\n";
cin.clear();
cin.ignore(123,'\n');
cout << "\nDeposit amount: RM ";
}
acc_balance = acc_balance + deposit;
cout<<"\nMoney deposit success. The money has been deposited to your account."
<<"\nYour current account balance is: RM "<<acc_balance<<endl;
break;
case 5: //reload TnG card
cout<<"Reload Touch 'N Go card:\n"
<<"Account balance: RM "<<acc_balance
<<"\nReload Value: RM ";
while(!(cin >> reload)) //filter out chars
{
cout <<"This is not integers! Try again!\n";
cin.clear();
cin.ignore(123,'\n');
cout << "\nReload Value: RM ";
}
if (reload <= acc_balance){
acc_balance = acc_balance - reload;
cout<<"Reload to (Enter Touch 'N Go card number):";
cin>>recepient;
cout<<"\nCard reload success. The money has been deducted from your account."
<<"\nYour current account balance is: RM "<<acc_balance<<endl;
if (acc_balance == 0){
cout<<"You have no money now!!";
}
}
else{
cout<<"The transfer amount is too much! Not enough in account balance!";
}
break;
case 6: //clear screen
system("cls");
break;
case 0:
cout<<"Thank you for using this program!"<<endl;
system("pause");
break;
default:
cout<<"Sorry, this action cannot be done. Please try again.";
break;
}
}while(option != 0);
}
int main(){
system("color 0e"); //change the color of the terminal to yellow
cout<<"-~-~-~-~-~-~-~-~-~-~-~-~-~-~-Welcome-~-~-~-~-~-~-~-~-~-~-~-~-~-~-\n";
cout<<"---------------------------created by BP-------------------------\n";
login();
system("cls");
system("color 03");
if(safety_pin == safety_pin1){ //user 1 menu
name = name1;
acc_num = acc_num1;
acc_balance = acc_balance1;
cout<<"\nName: "<<name;
cout<<"\nAccount number: "<<acc_num<<endl;
do{
action();
}while(option != 0);
}
else if(safety_pin == safety_pin2){ //user 2 menu
name = name2;
acc_num = acc_num2;
acc_balance = acc_balance2;
cout<<"\nName: "<<name;
cout<<"\nAccount number: "<<acc_num<<endl;
do{
action();
}while(option != 0);
}
else if(safety_pin == safety_pin3){ //user 3 menu
name = name3;
acc_num = acc_num3;
acc_balance = acc_balance3;
cout<<"\nName: "<<name;
cout<<"\nAccount number: "<<acc_num<<endl;
do{
action();
}while(option != 0);
}
return 0;
}