-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
228 lines (218 loc) · 6.92 KB
/
main.cpp
File metadata and controls
228 lines (218 loc) · 6.92 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
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
#include <iostream>
#include <string>
#include <vector>
#include "Account.h"
#include <windows.h>
#include "../../../source/repos/BankAccount/BankAccount/Accounts.h"
using namespace std;
//Consider adding a transfer money option and changing account option
/*Make a case where once they add a new account, everything is handled within that case
and if they logout, they return to the main menu. There they can add a new account.*/
void show_list();
void main_menu();
string name();
char get_choice();
void add_account(vector <Account>& accounts, Accounts& my_accounts, string name);
int choose_account();
void welcome(vector <Account>& accounts, Accounts& my_accounts, int i);
void show_list(){
cout << "\n1.) Set Balance." << endl;
cout << "2.) Deposit." << endl;
cout << "3.) Withdrawal." << endl;
cout << "4.) Check Balance." << endl;
cout << "5.) Transfer Funds." << endl;
cout << "6.) Delete Account." << endl;
cout << "L.) Logout." << endl;
cout << endl;
}
void main_menu() {
cout << "\n1.) Add New Account." << endl;
cout << "2.) Log-in to Existing Account." << endl;
cout << "E.) Exit" << endl;
cout << endl;
}
string name() {
char choice;
string name;
string error = "false";
string savings{ "Savings" };
string checkings{ "Checkings" };
cout << "1.) Savings" << endl;
cout << "2.) Checkings" << endl;
cout << "3.) Custom Account" << endl;
choice = get_choice();
cin.ignore();
if (choice == '1')
return savings;
if (choice == '2')
return checkings;
if (choice == '3')
{
cout << "Enter account name: ";
getline(cin, name);
return name;
}
else
{
cout << "Invalid Choice" << endl;
return error;
}
}
char get_choice() {
char choice;
cout << "\nEnter your choice: ";
cin >> choice;
cout << endl;
return choice;
}
void add_account(vector <Account>& accounts, Accounts& my_accounts,string name) {
if (my_accounts.add_account(accounts, name))
{
cout << "Account Added: " << name << endl;
cout << "Account is ready for log-in!" << endl;
}
else
{
cout << name << " already exists as an account." << endl;
}
}
int choose_account() {
int account;
cout << "Choose an account: ";
cin >> account;
cout << endl;
return account;
}
void welcome(vector <Account>& accounts, Accounts& my_accounts, int i){
cout << "=================================" << endl;
cout << "Managing Account: " << accounts[i].get_name() << endl;
cout << "=================================" << endl;
}
int main(){
vector <Account> accounts;
Accounts my_accounts;
string add_name;
bool managing_menu{true};
bool managing_account{false};
cout << "========================================" << endl;
cout << "Welcome to your Bank Account Manager." << endl;
cout << "========================================" << endl;
Sleep(1000);
while (managing_menu)
{
main_menu(); //Display Menu
char choice = get_choice();
cin.ignore();
switch (choice) {
case '1':
{ //If they create a new account, we create a case to add the acct and display the acct manager
add_name = name();
if (add_name == "false")
break;
add_account(accounts, my_accounts, add_name);
break;
}
case '2': //make sure to check if accounts exists first, let user know that no acct exists and send back to menu
{
if (!(my_accounts.display_accounts(accounts))) {
cout << "No Accounts to Display." << endl;
break;
}
int i = choose_account() - 1;
welcome(accounts, my_accounts, i);
managing_account = true;
while (managing_account) {
show_list();
char choice = get_choice();
cin.ignore();
switch (choice) {
case '1':
{
long double bal;
cout << "Set your balance: $";
cin >> bal;
while (bal < 0) {
cout << "\nCannot be a negative value!" << endl;
cout << "Enter your balance: $";
cin >> bal;
}
my_accounts.set_account_balance(accounts, i, bal);
break;
}
case '2':
{
long double dep{};
cout << "Enter your deposit: $";
cin >> dep;
while (dep < 0) {
cout << "\nCannot be a negative value!" << endl;
cout << "Enter your deposit: $";
cin >> dep;
}
my_accounts.account_deposit(accounts, i, dep);
break;
}
case '3':
{
long double wthdrl;
cout << "Withdraw: $";
cin >> wthdrl;
while (wthdrl < 0) {
cout << "\nCannot be a negative value!" << endl;
cout << "Withdraw: $";
cin >> wthdrl;
}
my_accounts.account_withdraw(accounts, i, wthdrl);
break;
}
case '4':
{
my_accounts.view_balance(accounts, i);
break;
}
case '5':
{
my_accounts.transfer(accounts, i);
break;
}
case '6':
{
char user_choice;
cout << "\nAre you sure? (Y/N): ";
cin >> user_choice;
if (tolower(user_choice) == 'y') {
my_accounts.delete_account(accounts, i);
managing_account = false;
break;
}
else
break;
}
case ('l'):
case ('L'):
{
cout << "Goodbye, "; my_accounts.name(accounts, i);
managing_account = false;
break;
}
default:
cout << "Invalid Choice." << endl;
break;
}
}
break;
}
case 'e':
case 'E':
{
cout << "Exiting Account Manager..." << endl;
managing_menu = false;
break;
}
default:
cout << "Invalid Choice." << endl;
break;
}
}
return 0;
}