-
Notifications
You must be signed in to change notification settings - Fork 0
/
ATM SIMULATOR.c
71 lines (61 loc) · 1.71 KB
/
ATM SIMULATOR.c
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
#include <stdio.h>
float balance = 1000; // Initial balance
void displayMenu() {
printf("\nATM Simulator Menu:\n");
printf("1. Deposit\n");
printf("2. Withdraw\n");
printf("3. Check Balance\n");
printf("4. Exit\n");
}
void deposit() {
float amount;
printf("Enter deposit amount: ");
scanf("%f", &amount);
if (amount > 0) {
balance += amount;
printf("Deposit successful. New balance: %.2f", balance);
} else {
printf("Invalid amount. Please enter a positive value.");
}
}
void withdraw() {
float amount;
printf("Enter withdrawal amount: ");
scanf("%f", &amount);
if (amount > 0 && amount <= balance) {
balance -= amount;
printf("Withdrawal successful. New balance: %.2f", balance);
} else if (amount <= 0) {
printf("Invalid amount. Please enter a positive value.");
} else {
printf("Insufficient funds. Withdrawal failed.");
}
}
void checkBalance() {
printf("Your current balance: %.2f", balance);
}
int main() {
int choice;
do {
displayMenu();
printf("\nEnter your choice (1-4): ");
scanf("%d", &choice);
switch (choice) {
case 1:
deposit();
break;
case 2:
withdraw();
break;
case 3:
checkBalance();
break;
case 4:
printf("Exiting ATM simulator. Thank you!");
break;
default:
printf("Invalid choice. Please enter a number between 1 and 4.");
}
} while (choice != 4);
return 0;
}