-
Notifications
You must be signed in to change notification settings - Fork 231
Expand file tree
/
Copy pathatm.c
More file actions
75 lines (63 loc) · 1.86 KB
/
atm.c
File metadata and controls
75 lines (63 loc) · 1.86 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
#include <stdio.h>
// Initialized the account balance to $1000
double accountBalance = 1000.0;
// Function to display the account balance
void checkBalance() {
printf("Your account balance is $%.2lf\n", accountBalance);
}
// Function to deposit money
void deposit() {
double amount;
printf("Enter the amount to deposit: $");
scanf("%lf", &amount);
if (amount > 0) {
accountBalance += amount;
printf("Deposit successful. Your new balance is $%.2lf\n", accountBalance);
} else {
printf("Invalid amount. Please enter a positive value.\n");
}
}
// Function to withdraw money
void withdraw() {
double amount;
printf("Enter the amount to withdraw: $");
scanf("%lf", &amount);
if (amount > 0 && amount <= accountBalance) {
accountBalance -= amount;
printf("Withdrawal successful. Your new balance is $%.2lf\n", accountBalance);
} else if (amount <= 0) {
printf("Invalid amount. Please enter a positive value.\n");
} else {
printf("Insufficient funds. Your current balance is $%.2lf\n", accountBalance);
}
}
int main() {
int choice;
printf("Welcome to the ATM\n");
while (1) {
printf("\nOptions:\n");
printf("1. Check Balance\n");
printf("2. Deposit\n");
printf("3. Withdraw\n");
printf("4. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
checkBalance();
break;
case 2:
deposit();
break;
case 3:
withdraw();
break;
case 4:
printf("Thank you for using the ATM. Goodbye!\n");
return 0;
default:
printf("Invalid choice. Please try again.\n");
}
}
return 0;
}