-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBanking_System.cpp
384 lines (377 loc) · 11.2 KB
/
Banking_System.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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct account
{
int accno;
char name[100];
int password;
int avb;
};
int i = 0;
int failure_admin = 0;
int failure_user = 0;
struct account ac[10];
void heading()
{
printf("***********************************************************************************************************************************************************\n");
printf("-----------------------------------------------------------------------------------------------------------------------------------------------------------\n");
printf("\t\t\t\t\t\t\t\t");
printf("BANKING SYSTEM\n");
printf("-----------------------------------------------------------------------------------------------------------------------------------------------------------\n");
printf("***********************************************************************************************************************************************************\n");
printf("\n");
}
int random(int h, int l)
{
int num = (rand()%(h-l+1)) + l;
return num;
}
int admin()
{
int p, f = 0;
int y = 1;
heading();
printf("Enter admin password:\n");
scanf("%d",&p);
system("cls");
heading();
if(p==1234)
{
int ch;
while(1)
{
printf("\t\t\t\t\t\t\t\tWELCOME ADMIN!\n\n");
printf("\t\t\t\t\t\t\t\t1. Open Account\n");
printf("\t\t\t\t\t\t\t\t2. Close Account\n");
printf("\t\t\t\t\t\t\t\t3. Exit from Admin Mode\n");
printf("\nEnter your choice:\n");
scanf("%d",&ch);
switch(ch)
{
case 1:
if(i!=9)
{
printf("Enter account number:\n");
scanf("%d",&ac[i].accno);
for(int b = 0;b<i;b++)
{
if(ac[i].accno == ac[b].accno)
{
printf("Account number already exits!\n");
continue;
}
}
printf("Enter name:\n");
scanf("%s",ac[i].name);
ac[i].password = random(1000, 9999);
ac[i].avb = 1000;
printf("Password: %d\n", ac[i].password);
printf("Account created successfully\n");
i++;
printf("Do you want to continue? Press 1 to continue and 0 to exit admin mode\n");
scanf("%d",&y);
if(y==1)
{
system("cls");
heading();
continue;
}
else
{
return 0;
}
}
else
{
printf("Account Limit Reached!\n");
}
break;
case 2:
int a;
printf("Enter account number:\n");
scanf("%d",&a);
for(int b = 0;b<i;b++)
{
if(a==ac[b].accno)
{
f = 1;
ac[b].accno = 0;
char x[100];
strcpy(x, ac[b].name);
int t = 0;
while(x[t]!='\0')
{
x[t] = '\0';
t++;
}
strcpy(ac[b].name, x);
ac[b].avb = 0;
ac[b].password = 0;
}
}
if(f==0)
{
printf("Account not found!\n");
continue;
}
printf("Do you want to continue? Press 1 to continue and 0 to exit admin mode\n");
scanf("%d",&y);
if(y==1)
{
system("cls");
heading();
continue;
}
else
{
return 0;
}
break;
case 3:
return 0;
default:
printf("Invalid Choice\n");
}
}
}
else
{
failure_admin++;
if(failure_admin <= 3)
{
printf("Incorrect Password! Press 1 to try again and 0 to exit admin mode\n");
scanf("%d",&y);
if(y==1)
{
system("cls");
admin();
}
else
{
return 0;
}
}
else
{
printf("3 incorrect attempts!!! Terminating Program....");
exit(0);
}
}
}
void deposit(int a)
{
int d, f = 0;
printf("Enter amount to be deposited:\n");
scanf("%d",&d);
for(int b= 0;b<i;b++)
{
if(a==ac[b].accno)
{
f = 1;
ac[b].avb = ac[b].avb + d;
printf("Rs. %d has been deposited to your account successfully\n",d);
break;
}
}
if(f==0)
{
printf("Account not found!\n");
}
}
void withdraw(int a)
{
int w, f = 0;
printf("Enter amount to be withdrawn:\n");
scanf("%d",&w);
for(int b = 0;b<i;b++)
{
f = 1;
if(a==ac[b].accno)
{
if(w <= (ac[b].avb - 1000))
{
ac[b].avb = ac[b].avb - w;
printf("Rs. %d has been withdrawn from your account successfully\n",w);
break;
}
else
{
printf("Insufficient Balance! Minimum balance must be Rs. 1000\n");
}
}
}
if(f==0)
{
printf("Account not found!\n");
}
}
void details(int a)
{
int f = 0;
printf("\n\t\t\t\t\t\t\t\tACCOUNT DETAILS\n");
for(int b = 0;b<i;b++)
{
if(a==ac[b].accno)
{
f = 1;
printf("\n");
printf("\t\t\t\t\t\t\t\tAccount Number: %d\n",ac[b].accno);
printf("\t\t\t\t\t\t\t\tName: %s\n",ac[b].name);
printf("\t\t\t\t\t\t\t\tBalance: Rs. %d\n\n",ac[b].avb);
break;
}
}
if(f==0)
{
printf("Account not found!\n");
}
}
int user()
{
int a, f = 0;
int ch, p;
int y = 0;
heading();
printf("Enter account number:\n");
scanf("%d",&a);
printf("Enter password:\n");
scanf("%d",&p);
for(int b = 0;b<i;b++)
{
if(a==ac[b].accno)
{
if(p==ac[b].password)
{
printf("\n");
strupr(ac[b].name);
system("cls");
heading();
printf("\t\t\t\t\t\t\t\tWELCOME %s\n\n", ac[b].name);
f = 1;
while(1)
{
printf("\t\t\t\t\t\t\t\t1. Deposit\n");
printf("\t\t\t\t\t\t\t\t2. Withdraw\n");
printf("\t\t\t\t\t\t\t\t3. Display Balance and Details\n");
printf("\t\t\t\t\t\t\t\t4. Exit from User Mode\n");
printf("\nEnter your choice:\n");
scanf("%d",&ch);
switch(ch)
{
case 1:
deposit(ac[b].accno);
details(ac[b].accno);
printf("Do you want to continue? Press 1 to continue and 0 to exit user mode\n");
scanf("%d",&y);
if(y==1)
{
continue;
}
else
{
system("cls");
return 0;
}
break;
case 2:
withdraw(ac[b].accno);
details(ac[b].accno);
printf("Do you want to continue? Press 1 to continue and 0 to exit user mode\n");
scanf("%d",&y);
if(y==1)
{
continue;
}
else
{
system("cls");
return 0;
}
break;
case 3:
details(ac[b].accno);
printf("Do you want to continue? Press 1 to continue and 0 to exit user mode\n");
scanf("%d",&y);
if(y==1)
{
continue;
}
else
{
system("cls");
return 0;
}
break;
case 4:
system("cls");
return 0;
break;
default:
printf("Invalid Choice\n");
}
}
}
else
{
failure_user++;
if(failure_user <= 3)
{
printf("Incorrect Password! Press 1 to try again and 0 to exit user mode.\n");
scanf("%d",&y);
if(y==1)
{
system("cls");
user();
}
else
{
return 0;
}
}
else
{
printf("3 incorrect attempts!!! Terminating program....\n");
exit(0);
}
}
}
}
if(f==0)
{
printf("Account not found!\n");
}
}
int main()
{
int x = 1;
while(1)
{
printf("\n");
heading();
int ch;
printf("\t\t\t\t\t\t\t\t1. Admin Mode\n");
printf("\t\t\t\t\t\t\t\t2. User Mode\n");
printf("\t\t\t\t\t\t\t\t3. Exit\n");
printf("Enter your choice:\n");
scanf("%d",&ch);
switch(ch)
{
case 1:
system("cls");
x = admin();
system("cls");
break;
case 2:
system("cls");
user();
break;
case 3:
printf("Program Ends\n");
exit(0);
default:
printf("Invalid Choice!\n");
}
}
return 0;
}