I want to be store multiple bank accounts and access each of them. I want them all to have separate data.

This is what I have so far:
```
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
#include <iostream>
#include <string>
#include <vector>
#include <cctype>
using namespace std;

class bankAccounts{
    public: 
    
    bankAccounts()
    {

    }

void listOptions(){
cout<< "Choose an option from the menu."<<endl;
cout<< "1 - View Balance"<<endl;
cout<< "2 - Deposit"<<endl;
cout<< "3 - Withdrawl"<<endl;
cout<< "4 - View Transactions"<<endl;
cout<< "5 - Create New Account"<<endl;
cout<< "6 - Exit Session"<<endl;
}
void bankOptions(){

}
void accountNumGenerator(){
    int accNum = rand() % 999999;
    cout<<"You are officially a valued member at Towson Bank! "<<accNum<< " is your account number."<<endl;
}
};
int main(){
    int goBack;
   static vector<string>accountTransactions;
    float static accBalance = 0;
    float addMoney;
    float subtractMoney;
    bankAccounts app;
    string firstName;
    string lastName;
    string bankCreation;
    string newAcc;
    int amountOfAccs[10];
    int menuOptions;
    int count = 0;
    cout<<"Hello what is your first name?\n";
    cin>>firstName;
    cout<<"Hello what is your last name?\n";
    cin>>lastName;
    cout<<"Hello "<<firstName<<" "<<lastName<<"! Do you want to sign up for an account at Towson Bank?"<<endl;
    cout<<"Type in Yes if you want to continue with the proccess or No if you want to end this session."<<endl;
    cin>>bankCreation;
    while(count <= 10){
    if(bankCreation == "yes" || bankCreation == "Yes"){
        app.accountNumGenerator();
        app.listOptions();
        cin>>menuOptions;
        switch(menuOptions){
            case 1: 
            cout<<"This is your account balance: \n"<<"$"<<accBalance<<endl;
    cout<<"Press 1 to go back or 0 to end the session"<<endl;
    cin>>goBack;
    if(goBack == 0){
         break;
    }
    else if(goBack == 1){
app.listOptions();
app.bankOptions();
    }
            break;
            case 2:
            cout<<"How much do you want to depoist?"<<endl;
    cin>>addMoney;
    accBalance = accBalance + addMoney;
    accountTransactions.push_back("Deposited $" + to_string(addMoney));
    cout<<"Press 1 to go back or 0 to end the session"<<endl;
    cin>>goBack;
    if(goBack == 0){
        break;
    }
    else if(goBack == 1){
app.listOptions();
app.bankOptions();
    }  
    else if(goBack != 1 || goBack != 2){
        cout<<"Invalid Entry, we will be ending this session."<<endl;
        exit(1);
    }
            break;
            case 3:
            cout<<"How much do you want to withdrawl?"<<endl;
    cin>>subtractMoney;
    accBalance = accBalance - subtractMoney;
    accountTransactions.push_back("Withdrew $" + to_string(subtractMoney));
    cout<<"Press 1 to go back or 0 to end the session"<<endl;
    cin>>goBack;
    if(goBack == 0){
        break;
    }
    else if(goBack == 1){
app.listOptions();
app.bankOptions();
    }
    break;
            break;
            case 4:
            cout<<"These are your account transactions."<<endl;
cout<<accountTransactions[0]<<endl;
for(int i = 0; i < accountTransactions.size(); i++){
    cout<<accountTransactions[i]<< "\n";
}
cout<<"Press 1 to go back or 0 to end the session"<<endl;
    cin>>goBack;
    if(goBack == 0){
        break;
    }
    else if(goBack == 1){
app.listOptions();
app.bankOptions();
    }
            break;
            case 5:
            cout<<"New acc?"<<endl;
            cin>>newAcc;
            if(newAcc == "yes"){
                cout<<"ok"<<endl;
            }
            break;
            case 6:
               // cin>>amountOfAcc[0];
               cout<<"Thank you for being a valued member at Towson Bank!"<<endl;
exit(1);

default:
cout<<"Not a valid option, please choose again!"<<endl;
cout<< "Choose an option from the menu."<<endl;
cout<< "1 - View Balance"<<endl;
cout<< "2 - Deposit"<<endl;
cout<< "3 - Withdrawl"<<endl;
cout<< "4 - View Transactions"<<endl;
cout<< "5 - Exit Session"<<endl;
cin>>menuOptions;
app.listOptions();
app.bankOptions();
break;    
}
    }
else if(bankCreation == "No" || bankCreation == "no"){
    cout<<"Thank you for your time, we will be ending this session now."<<endl;
        exit(1);
}
            
else if(bankCreation != "No" || bankCreation != "no" || bankCreation != "Yes" || bankCreation != "yes"){
       
        cout<<"This is not a valid entry, please put in a valid response."<<endl;
        cout<<"Hello "<<firstName<<" "<<lastName<<"! Do you want to sign up for an account at Towson Bank?"<<endl;
    cout<<"Type in Yes if you want to continue with the proccess or No if you want to end this session."<<endl;
    cin>>bankCreation;
}
    
count++;
    }
    return 0;
}

```
Last edited on
Please use proper code tags. This forum doesn't support Markdown, but you can use [code] tags.

Also, instead of just throwing in a bunch of code, what is your specific problem or question?

What do you mean with "store multiple bank accounts"?

You just want to have multiple bankAccount objects at runtime, or actually need to persist them on the disk?
Last edited on
Hey, I'm sorry I'm new to this so I don't know how to use proper code tags and my problem is I want to have multiple bankAccounts when I want to create them so if I chose to I can have another account with its own data and I can choose to go back and forth between the two without have its data shared.
About using tags...
PLEASE learn to use code tags, they make reading and commenting on source code MUCH easier.

http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/

HINT: you can edit your post and add code tags.

Some formatting & indentation would not hurt either
Hey, I'm sorry I'm new to this so I don't know how to use proper code tags and my problem is I want to have multiple bankAccounts when I want to create them so if I chose to I can have another account with its own data and I can choose to go back and forth between the two without have its data shared.

This sounds very much like you want to implement a class BankAccount (note: no "...s" in the name!) that represents a single bank account. You can then have multiple instances (objects) of that class, so each object has its own separate state. That is how you solve these things in object-oriented programming :-D

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class BankAccount
{
    // Write your code for a *single* (specific) bank account here !!!
public:
    BankAccount(void)
    {
        m_value = 0;
    }
    void add(const int amount)
    {
        m_value += amount;
    }
protected:
    int m_value;
};


1
2
3
4
5
6
7
8
9
10
11
12
int main()
{
    // Create instances
    BankAccount bankAccount1;    // <-- create bank account #1
    BankAccount bankAccount2;    // <-- create bank account #2
    ...
    BankAccount bankAccountN;    // <-- create bank account #N

    // Now do something with your instances
    bankAccount1.add(13);        // <-- this accesses bank account #1
    bankAccount42.add(666);      // <-- this accesses bank account #42
}



Surely, when the number of bank accounts becomes huge, better use an array!

1
2
3
4
5
6
7
8
9
10
11
12
int main()
{
    // Create instances
    BankAccount *bankAccounts = new BankAccount[99991];

    // Do something with your instances
    bankAccounts[0].add(13);     // <-- this accesses bank account #1
    bankAccounts[41].add(666);   // <-- this accesses bank account #42

    // Clean up to avoid a memory leak!
    delete[] bankAccounts;
}



You get the idea, I hope...
Last edited on
Thank you man this helped a lot.
Topic archived. No new replies allowed.