-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
202 lines (154 loc) · 3.84 KB
/
main.c
File metadata and controls
202 lines (154 loc) · 3.84 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
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
#include <stdio.h>
#include "myBank.h"
int main(){
char letter;
double mode, accountNumber, dep, amount, remain, interes, open;
initial();
do{
printf("\n" );
printf("\n" );
printf("Please choose a transaction type:\nO-Open Account\nB-Balance Inquiry\nD-Deposit\nW-Withdrawal\nC-Close Account\nI-Interest\nP-Print\nE-Exit\n");
scanf(" %c",&letter);
switch (letter){
case 'O':
printf("Please enter amount for deposit: ");
if(scanf("%lf", &dep) == 0 ){
printf("Failed to read the amount");
break;
}
if(dep < 0){
printf("Invalid Amount");
break;
}
accountNumber = openAccount(dep);
if(accountNumber == -1){
printf("No room for new account!");
break;
}
else{
printf("New account number is: %.0lf", accountNumber);
break;
}
case 'B':
printf("Please enter account number: ");
if(scanf("%lf", &accountNumber) == 0){
printf("Failed to read the account number");
break;
}
if(accountNumber < 901 || accountNumber >950){
printf("Invalid account number");
break;
}
open = isOpen(accountNumber);
if(open == -1){
printf("This account is closed");
break;
}
amount = accountRemain(accountNumber);
printf("The balance of account number %.0lf is: %.2lf", accountNumber, amount);
break;
case 'D':
printf("Please enter account number: ");
if(scanf("%lf", &accountNumber) == 0){
printf("Failed to read the account number");
break;
}
if(accountNumber <901 || accountNumber >950){
printf("Invalid account number");
break;
}
open = isOpen(accountNumber);
if(open == -1 ){
printf("This account is closed");
break;
}
printf("Please enter the amount to deposit: ");
if(scanf("%lf", &amount) == 0){
printf("Failed to read the amount");
break;
}
if(amount<0){
printf("Cannot deposit a negative amount" );
break;
}
dep = deposit(amount, accountNumber);
printf("The new balance is: %.2lf", dep);
break;
case 'W':
printf("Please enter account number: ");
if(scanf("%lf", &accountNumber) == 0){
printf("Failed to read the account number");
break;
}
if(accountNumber < 901 || accountNumber >950){
printf("Invalid account number");
break;
}
open = isOpen(accountNumber);
if(open == -1 ){
printf("This account is closed");
break;
}
printf("Please enter the amount to withdraw: ");
if(scanf("%lf", &amount) == 0){
printf("Failed to read the amount");
break;
}
if(amount<0){
printf("\n");
printf("Cannot withdraw more than the balance" );
break;
}
remain = withdraw(amount,accountNumber);
if(remain == -1){
printf("This account is closed");
break;
}
if(remain == -2){
printf("Cannot withdraw more than the balance");
break;
}
printf("The new balance is: %.2lf", remain );
break;
case 'C':
printf("Please enter account number: ");
if(scanf("%lf", &accountNumber) == 0){
printf("Failed to read the account number");
break;
}
if(accountNumber < 901 || accountNumber >950){
printf("Invalid account number");
break;
}
open = isOpen(accountNumber);
if(open == -1){
printf("This account is closed");
break;
}
mode = closeAccount(accountNumber);
printf("Closed account number %.0lf",mode );
break;
case 'I':
printf("Please enter interest rate: ");
if(scanf("%lf", &interes) == 0){
printf("Failed to read the interest rate");
}
if(interes<-100){
printf("Invalid interest rate");
break;
}
interest(interes);
break;
case 'P':
printAll();
break;
case 'E':
closeAll();
return 0;
default:
printf("Invalid transaction type");
break;
printf("\n");
}
}while(letter!='E');
}