Banking application storing account info in array

Hello I've been working on a C++ banking application that should be able to hold more than one account with all the related field's. I have come across a few issues:

When displaying account info in Display or ShowInfo functions, the first letter of the first name and the middle initial wont show up.
When creating an account only the most recent account is able to be searched for and displayed in display data. I know that an array is needed for this to be possible, I'm just not sure if implemented this correctly.
Thanks for the help. Any input is appreciated!

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
#include <stdlib.h>
#include <conio.h>
#include <iostream>
#include <string>

using namespace std;

class BankAccount{
    double Balance = 0.0;
    char ans;
    public:struct Name{
        char Last_Name[50];
        char First_Name[50];
        char Middle_Initial[5];
    }Name;
    public:struct Account{
        char Type[1];
        int Account_Number;
    }Account;
    public:
    void CreateAccount();
    void Withdraw();
    void Deposit();
    void Display();
    void ShowInfo();
    int Menu();

};

void BankAccount::CreateAccount(){
    do
    {
        cout << "\nEnter account number: ";
        cin >> Account.Account_Number;
        cout << "\nEnter the last name for the account: ";
        cin.ignore();
        cin.getline(Name.Last_Name, 50);
        cout << "\nEnter the first name for the account: ";
        cin.ignore();
        cin.getline(Name.First_Name, 50);
        cout << "\nEnter the Middle initial for the account: ";
        cin.ignore();
        cin.getline(Name.Middle_Initial, 5);
        cout << "\nEnter the type of account (C/S) : ";
        cin >> Account.Type;
        cout << "\nEnter the initial balance of the account: ";
        cin >> Balance;
        cout << "\n\nAccount Created.";
        cout << "\n\nCreate new account? (Y/N) : ";
        cin >> ans;

        while (ans != 'Y' && ans != 'N'){
            cout << "Invalid input. Create new account? (Y/N) : ";
            cin >> ans;
        }
        cout << endl;
    } while (ans != 'N');
};
void BankAccount::Withdraw(){
    int actNum;
    double amount;
    cout << "Enter the account number for the account that you wish to withdraw funds: ";
    cin >> actNum;
    if (actNum == Account.Account_Number){
        cout << "Enter the amount you would like to withdraw: ";
        cin >> amount;
        Balance = Balance - amount;
    }
    else if (actNum != Account.Account_Number){
        cout << "No account found under that number! Try again!";
    }

}
void BankAccount::Deposit(){
    int actNum;
    double amount;
    cout << "Enter the account number for the account that you wish to deposit funds: ";
    cin >> actNum;
    if (actNum == Account.Account_Number){
        cout << "Enter the amount you would like to deposit: ";
        cin >> amount;
        Balance = Balance + amount;
    }
    else if (actNum != Account.Account_Number){
        cout << "No account found under that number! Try again!";
    }
}
void BankAccount::Display(){
    int actNum;
    cout << "Enter the account number for the account that you wish to display account information for: ";
    cin >> actNum;
    if (actNum == Account.Account_Number){
        cout << "Account details for " << Name.First_Name << " " << Name.Middle_Initial << " " << Name.Last_Name << "'s account: " << endl;
        cout << "Account Number: " << Account.Account_Number << endl;
        cout << "Account Type (Checking / Savings): " << Account.Type << endl;
        cout << "Account Balance:  $" << Balance << endl;
    }
    else if (actNum != Account.Account_Number){
        cout << "No account found under that number! Try again!";
    }

}
void BankAccount::ShowInfo(){
    cout << "Account details for " << Name.First_Name << " " << Name.Middle_Initial << " " << Name.Last_Name << "'s account: " << endl;
    cout << "Account Number: " << Account.Account_Number << endl;
    cout << "Account Type (Checking / Savings): " << Account.Type << endl;
    cout << "Account Balance:  $" << Balance << endl;    

}

int main(int argc, char *argv){
    BankAccount ob;
    char ch;

    cout << "Welcome to Console Banking Application V 1.0!";
    cout << "\nSelect an item from the list below by entering the corresponding letter.";
    do{
        cout << "\n\n A. Create Account \n B. Withdraw \n C. Deposit \n D. Show Account Details \n\n Q. Exit Application\n\n";
        ch = ob.Menu();
        switch (ch){
        case 'A':
        case 'a': ob.CreateAccount();
            ob.ShowInfo();
            break;
        case 'B': 
        case 'b': ob.Withdraw();
            break;
        case 'C':
        case 'c': ob.Deposit();
            break;
        case 'D':
        case 'd': ob.Display();
            break;
        case 'Q':
        case 'q': ob.ShowInfo();
                  exit(1);
            break;
        }

    } while (1);
}
int BankAccount::Menu(){
    char ch;
    cout << "Select an option: ";
    cin >> ch;
    return ch;
}

Last edited on
I know a for loop to accept the user's input and store in an array is necessary, I'm just not sure how to go about this. If someone could point me in the correct direction that would be awesome!!
Topic archived. No new replies allowed.