-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbankingprogram.c
More file actions
111 lines (82 loc) · 1.91 KB
/
Copy pathbankingprogram.c
File metadata and controls
111 lines (82 loc) · 1.91 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include <stdio.h>
void checkBalance(float balance);
float deposit();
float withdraw(float balance);
int main()
{
int choise = 0;
float balance = 0.0f;
printf("WELCOME TO THE BANK!\n");
do
{
printf("\nSelect an option: \n");
printf("1. Check balance\n");
printf("2. Deposit money\n");
printf("3. Withdraw money\n");
printf("4. Exit\n");
printf("\nEnter your choise: ");
scanf("%d", &choise);
switch (choise)
{
case 1:
checkBalance(balance);
break;
case 2:
balance += deposit();
checkBalance(balance);
break;
case 3:
balance -= withdraw(balance);
checkBalance(balance);
break;
case 4:
printf("\nThank you for using the bank!\n");
break;
default:
printf("\nInvalid choise! Please select 1 - 4\n");
break;
}
} while (choise != 4);
return 0;
}
void checkBalance(float balance)
{
printf("\nYour current balance is: $%.2f\n", balance);
}
float deposit()
{
float amount = 0.0f;
printf("\nEnter amount to deposit: $");
scanf("%f", &amount);
if(amount < 0)
{
printf("\nInvalid amount!\n");
return 0;
}
else
{
printf("\nSuccessfully deposited $%.2f\n", amount);
return amount;
}
}
float withdraw(float balance)
{
float amount = 0.0f;
printf("\nEnter amount to withdraw: $");
scanf("%f", &amount);
if(amount < 0)
{
printf("\nInvalid amount!\n");
return 0;
}
else if(amount > balance)
{
printf("\nInsufficient funds! Your balance is $%.2f\n", balance);
return 0;
}
else
{
printf("\nSuccessfully withdrew $%.2f\n", amount);
return amount;
}
}