-
Notifications
You must be signed in to change notification settings - Fork 0
/
BankSystem.cpp
275 lines (229 loc) · 5.78 KB
/
BankSystem.cpp
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
#include <iostream>
#include <string>
#include <string.h>
#include <fstream>
#include <cstdlib>
#include <iomanip>
// ID, Total, Username
using namespace std;
// Data
void info (int[], int[], string[]);
void newuser (int&, int[], int[], string[]);
void returninguser (int&, int[], int[], string[]);
int socialsecurity(int&);
// Writing
void database(int&, int&, int&, string&);
// Functions
void menu(int&, int&, int[], int[], string[]);
void accountlookup(int&, int&, int[], int[], int&, string[]);
void readin(int&, int[], int[], string[]);
void cleanup(int[], int[]);
void validator(int&);
void uservalidator(int&);
void spacing();
int main() {
int
id[500],
total[500],
choice = 0,
useridnumber = 0;
string
name[500];
cleanup(id, total);
readin(useridnumber, id, total, name);
menu(choice, useridnumber, id, total, name);
}
void readin(int& userindatabase, int id[], int total[], string user[]) {
string line, line2;
ifstream readdatabase;
int pos, fix;
readdatabase.open("Database.txt");
if (!readdatabase) {
cout << "This machine is out of order" << endl;
exit(0);
}
while (getline(readdatabase, line)) {
cout << line << endl;
line2 = line.substr(0, line.find(" "));
fix = line2 - 0;
//line.(0, fix);
cout << "This is the fix " << endl;
}
readdatabase.close();
}
void menu(int& choice, int& useridnumber, int id[], int total[], string user[]) {
cout << "Welcome To The Terminal Bank" << endl;
cout << "1. New User" << endl;
cout << "2. Returning User" << endl;
cout << "6. Quit" << endl;
cin >> choice;
validator(choice);
while (choice != 6) {
switch (choice) {
case 1:
newuser(useridnumber, id, total, user);
break;
case 2:
returninguser(useridnumber, id, total, user);
break;
case 6:
exit(0);
break;
}
}
//info(, total, newname);
menu(choice, useridnumber, id, total, user);
}
void validator(int& choice) {
bool input;
if (choice == 1)
input = true;
else if (choice == 2)
input = true;
else if (choice == 6)
input = true;
else
input = false;
while (input == false) {
cout << "Your input is invalid, please try again" << endl;
cin >> choice;
if (choice == 1)
input = true;
else if (choice == 2)
input = true;
else if (choice == 6)
input = true;
else
input = false;
}
}
void newuser(int& useridnumber, int newid[], int total[], string newname[]) {
system("CLS");
cout << "Please put in your name: ";
cin >> newname[0];
info(newid, total, newname);
srand(time(0));
newid[0] = (rand() % 20) + 10 + (rand() % 30) + 100 + (rand() % 10) + 1000 + (rand() % 15) + 10000;
cout << "Welcome to your new bank " << newname[0] << " here's your bank ID" << endl;
cout << "ID#:s " << newid[0] << endl;
info(newid, total, newname);
// useridnumber = useridnumber + 1
}
int socialsecurity(int& conf) {
return 0;
}
void info(int newid[], int total[], string newname[]) {
system("CLS");
cout << "Bank #: " << newid[0] << " Total Balance: " << total[0] << " User: " << newname[0] << endl;
cout << "----------------------------" << endl;
}
void database(int& id, int& balance, int& total, string& name) {
ofstream storage;
storage.open("Database.txt");
storage << "Bank Number: " << id << "\n " << "Total Balance: " << balance << "\n " << "Account User Name: " << name << endl;
storage.close();
}
void returninguser(int& useridnumber, int id[], int total[], string user[]) {
int choice,
inputid;
cout << "Please enter your ID." << endl;
cout << "ID#: ";
cin >> inputid;
//accountlookup(inputid, id, total, user);
cout << "1. Deposit" << endl;
cout << "2. Withdrawal" << endl;
cout << "3. Check Account" << endl;
cout << "4. Delete Account" << endl;
cout << "6. Quit" << endl;
cin >> choice;
uservalidator(choice);
while (choice != 6) {
switch (choice) {
case 1:
break;
case 2:
info(id, total, user);
break;
case 3:
info(id, total, user);
break;
case 4:
info(id, total, user);
break;
case 6:
exit(0);
break;
}
}
}
void uservalidator(int& choice) {
bool input;
if (choice == 1)
input = true;
else if (choice == 2)
input = true;
else if (choice == 3)
input = true;
else if (choice == 4)
input = true;
else if (choice == 6)
input = true;
else
input = false;
while (input == false) {
cout << "Your input is invalid, please try again" << endl;
cin >> choice;
if (choice == 1)
input = true;
else if (choice == 2)
input = true;
else if (choice == 3)
input = true;
else if (choice == 4)
input = true;
else if (choice == 6)
input = true;
else
input = false;
}
}
void accountlookup(int& useridnumber, int& inputid, int id[], int total[], string user[]) {
for (int i = 0; i <= 500; i++) {
if (inputid == id[i]) {
// 11504 == id[5];
// id[useridnumber]
// useridnumber = i
break;
}
}
info(id, total, user);
}
void spacing() {
cout << endl;
cout << endl;
}
void cleanup(int id[], int total[]) {
for (int i = 0; i <= 500; i++)
id[i] = 0, total[i] = 0;
}
/*
Revised code
int samenumber = 0;
cout << "Please get a pen and paper and write down your new ID: ";
// To generate a new number and self check if it exist. If the database is full, we'll get an error message saying its full "Please visit another branch".
for (int num = 0; num <= 500; num++) {
newids[num] = rand() % 20;
// cout << "THIS IS ACCOUNT NUMBER " << num << "AND THE ACCOUNT NUMBER IS " << newids[num] << endl;
for (int check = 1; check <= 500; check++) {
// cout << "THIS IS CHECK NUMBER " << check << endl;
if (newids[check] == newids[num]) {
if (newids[check] == newids[num]) {
cout << "ID: " << newids[num] << " is the same as Account# " << check << " in the database and that ID is: " << newids[check] << endl;
newids[num] = rand() % 200 + 1;
samenumber++;
}
}
}
// cout << newids[num] << endl;
// cout << endl;
*/