-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmyBank.c
More file actions
95 lines (80 loc) · 2.02 KB
/
myBank.c
File metadata and controls
95 lines (80 loc) · 2.02 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
#include <stdio.h>
#include "myBank.h"
#define R 50
#define C 3
double accounts [R][C] ={0};
char letter;
double dep, getAccountNum, accountNumber, amount, interes;
int accoutNum = 901;
//initial array to 0
void initial(){
for(int i=0; i < R; i++){
accounts[i][0]=0;//closed or opened - first initiation to close
accounts[i][1]=accoutNum;//the account number
accounts[i][2]=0;//remained cash
accoutNum++;
}
}
double isOpen(double accountNumber){
if(accounts[(int)accountNumber-901][0] == 0){
return -1;
}
return 0;
}
double openAccount(double amount){
getAccountNum = -1;
for (int i = 0; i < R; ++i){
if(accounts[i][0] == 0){
getAccountNum = accounts[i][1];
accounts[i][2] = amount;
accounts[i][0] = 1;
break;
}
}
return getAccountNum;
}
double accountRemain(double accountNumber){
return accounts[(int)accountNumber-901][2];
}
double deposit (double amount, double accountNumber){
if(accounts[(int)accountNumber-901][0] == 0){
return -1;
}
accounts[(int)accountNumber-901][2] += amount;
return accounts[(int)accountNumber-901][2];
}
double withdraw(double amount, double accountNumber){
if(accounts[(int)accountNumber-901][2] < amount){
return -2;
}
accounts[(int)accountNumber-901][2] -= amount;
return accounts[(int)accountNumber-901][2];
}
double closeAccount(double accountNumber){
accounts[(int)accountNumber-901][2] = 0;
accounts[(int)accountNumber-901][0] = 0;
return accountNumber;
}
void interest (double interes){
for (int i = 0; i < R; ++i){
if(accounts[i][0] != 0){//only if the account is opened
accounts[i][2] *= (100+interes)/100;
}
}
}
void printAll(){
for (int i = 0; i < R; ++i){
if(accounts[i][0] != 0){
printf("The balance of account number %.0lf is: %.2lf", accounts[i][1], accounts[i][2]);
printf("\n" );
}
}
}
void closeAll(){
for(int i = 0; i<R; i++){
if(accounts[i][0] != 0){
accounts[i][0] = 0;
accounts[i][2] = 0;
}
}
}