-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBank.c
More file actions
91 lines (76 loc) · 2.5 KB
/
Bank.c
File metadata and controls
91 lines (76 loc) · 2.5 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
#include <stdio.h>
#include <string.h>
#include <unistd.h>
int main() {
char username[50];
int pin, enteredPin;
int balance = 5000;
int choice, amount;
int attempts = 3;
printf("Enter username: ");
scanf("%49s", username);
printf("Set your 4-digit ATM PIN: ");
scanf("%d", &pin);
if (pin < 1000 || pin > 9999) {
printf("Invalid PIN. Please restart and enter a 4-digit PIN.\n");
return 0;
}
printf("\n--- Welcome %s to Srihan Mini ATM ---\n", username);
sleep(1);
while (attempts > 0) {
printf("Enter your ATM PIN: ");
scanf("%d", &enteredPin);
if (enteredPin == pin) {
printf("PIN Verified.\n");
break;
} else {
attempts--;
printf("Incorrect PIN. Attempts left: %d\n", attempts);
if (attempts == 0) {
printf("Too many failed attempts. Exiting.\n");
return 0;
}
}
}
do {
printf("\n===== ATM MENU =====\n");
printf("1. Check Balance\n");
printf("2. Deposit Money\n");
printf("3. Withdraw Money\n");
printf("4. Exit\n");
printf("Choose an option (1-4): ");
scanf("%d", &choice);
switch(choice) {
case 1:
printf(" Your current balance is: ₹%d\n", balance);
break;
case 2:
printf("Enter amount to deposit: ₹");
scanf("%d", &amount);
if (amount > 0) {
balance += amount;
printf("Deposit successful. New balance: ₹%d\n", balance);
} else {
printf("Invalid deposit amount.\n");
}
break;
case 3:
printf("Enter amount to withdraw (Available ₹%d): ₹", balance);
scanf("%d", &amount);
if (amount > 0 && amount <= balance) {
balance -= amount;
printf("Withdrawal successful. New balance: ₹%d\n", balance);
} else {
printf("Invalid amount or insufficient balance.\n");
}
break;
case 4:
printf(" Thank you for using Srihan Mini ATM. Goodbye!\n");
break;
default:
printf("❗Invalid choice. Please try again.\n");
}
sleep(1);
} while(choice != 4);
return 0;
}