I'm struggling trying to complete the rest of my C++ program

Code: http://pastebin.com/m3e26ab95

The program lets the user be the customer, banker, or supervisor, and all of their privileges involve structs. I made an array of 100 structs for 100 potential customers, and I need to do something similar for banking.

I'm trying to put customer and banker's info detailed in that struct into a list on a text file that opens at the program startup, reads from it, writes to it, etc...otherwise users need to remake their account EVERY time they use the program

I need help finishing that part, and any additional stuff would be fan-TAST-ic...
You could start by breaking up the thing using smaller functions rather than using one long function. I just don't want to read all that stuff in main (maybe someone else might).

It might help if you used the standard string type and stanard collections rather than using char arrays for strings and fixed arrays for collections.
Kind of like this? I'm unsure about reading/writing to files though, everything to do with file I/O, the struct

struct customerInfo{ char firstName[20]; char lastName[20]; float amount; AccountType type;};

is how I want object in the file to be stored as, e.g.

"Carol Burns
$423.04
Checking

Brandon Jay
$0.01
Credit" etc...

The trouble is reading from/writing to these abnoxious files

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
#include <iostream>
#include <cctype>

using namespace std;

enum AccountType
    { unknown = -1, Checking, Savings, CreditCard, InstantAccess };

enum MenuType {
    Main, CustomerMenu, EmployeeMenu, SupervisorMenu
};

enum MenuSelection {
    None = -1,
    Customer='1', Employee='2', Supervisor='3', // main menu options
    Balance='a', Deposit, Withdrawal, Transfer, Other, // customer options
    AddCustomer, DeleteCustomer, SearchCustomer, // employee options
    CustomerCount, MoneyTotal, DailyDepositTotal, // supervisor options
    DailyWithdrawalTotal, TransactionLog,
    Quit='q'
};

struct customerInfo {
    char firstName[20];
    char lastName[20];
    float amount;
    AccountType type;
} customerInfo[100];

MenuSelection menu(const MenuType);
void menuAction(const MenuSelection);

int main(int argc, char *argv[]) {
    MenuSelection menuSel = None;

    while (menuSel != Quit) {
        switch (menuSel = menu(Main)) {
        case Customer:
            menuAction(menuSel = menu(CustomerMenu));
            break;
        case Employee:
            menuAction(menuSel = menu(EmployeeMenu));
            break;
        case Supervisor:
            menuAction(menuSel = menu(SupervisorMenu));
            break;
        case Quit:
            cout << "You have chosen to quit, we appreciate your business.";
            break;
        default:
            cout << "You have entered an invalid option, please try again." << endl;
            break;
        }
    }
    return 0;
}

MenuSelection menu(const MenuType menu) {
    char opt = (menu == Main) ? '1' : 'A';
    char choice;

    switch (menu) {
    case Main:
        cout << "Welcome To the Bank!" << endl;
        cout << "Please enter an option." << endl;
        cout << " " << opt << ") Customer" << endl;
        cout << " " << char(++opt) << ") Bank Employee" << endl;
        cout << " " << char(++opt) << ") Bank Supervisor" << endl;
        break;
    case CustomerMenu:
    case EmployeeMenu:
    case SupervisorMenu:
        if (menu == CustomerMenu) {
            cout << "Customer ";
        } else if (menu == EmployeeMenu) {
            cout << "Employee ";
        } else if (menu == SupervisorMenu) {
            cout << "Supervisor ";
        }
        cout << "Services" << endl;
        cout << "Please enter an option:" << endl << endl;
        cout << " " << opt << ") Balance Inquiry" << endl;
        cout << " " << char(++opt) << ") Deposit Funds" << endl;
        cout << " " << char(++opt) << ") Withdraw funds" << endl;
        cout << " " << char(++opt) << ") Transfer Funds" << endl;
        cout << " " << char(++opt) << ") Other" << endl;
        if ((menu == EmployeeMenu) || (menu == SupervisorMenu)) {
            cout << " " << char(++opt) << ") Add a new Customer to the Bank" << endl;
            cout << " " << char(++opt) << ") Delete a Customer from the Bank" << endl;
            cout << " " << char(++opt) << ") Search for a customer's Record" << endl;
        }
        if (menu == SupervisorMenu) {
            cout << " " << char(++opt) << ") Total Customers in Bank" << endl;
            cout << " " << char(++opt) << ") Total Money in the Bank" << endl;
            cout << " " << char(++opt) << ") Total Deposits in a Day" << endl;
            cout << " " << char(++opt) << ") Total Withdrawals in a Day" << endl;
            cout << " " << char(++opt) << ") Log of all transactions" << endl;
        }
        break;
    };
    cout << " Q) Quit the application." << endl << "> ";
    cin >> choice;
    return static_cast<MenuSelection>( tolower(choice) );
}

void menuAction(const MenuSelection menuSel) {
    switch (menuSel) {
    case Balance:
        cout << "balance inquiry tbd" << endl;
        break;
    case Deposit:
        cout << "deposit tbd" << endl;
        break;
    case Withdrawal:
        cout << "withdrawal tbd" << endl;
        break;
    case Transfer:
        cout << "transfer tbd" << endl;
        break;
    case Other:
        cout << "other tbd" << endl;
        break;
    case AddCustomer:
        cout << "add customer tbd." << endl;
        break;
    case SearchCustomer:
        cout << "search customer tbd." << endl;
        break;
    case DeleteCustomer:
        cout << "delete customer tbd." << endl;
        break;
    case CustomerCount:
        cout << "customer count tbd." << endl;
        break;
    case MoneyTotal:
        cout << "money total tbd." << endl;
        break;
    case DailyDepositTotal:
        cout << "deposit total tbd." << endl;
        break;
    case DailyWithdrawalTotal:
        cout << "withdrawal total tbd." << endl;
        break;
    case TransactionLog:
        cout << "transaction log tbd." << endl;
        break;
    case Quit:
        cout << "You have chosen to quit, we appreciate your business.";
        break;
    default:
        cout << "You have entered an invalid option, please try again." << endl;;
        break;
    }
}
Here's an example that writes the file. Give the read a try.

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
#include <iostream>
#include <ostream>
#include <fstream>

enum AccountType
    { unknown = -1, Checking, Savings, CreditCard, InstantAccess };

struct customerInfo {
    char firstName[20];
    char lastName[20];
    float amount;
    AccountType type;
};

std::ostream& save(std::ostream &os, const customerInfo &info)
{
        os << info.firstName << ' ' << info.lastName << std::endl;
        os << info.amount << std::endl;
        switch (info.type)
        {
        case Checking:
                os << "Checking" << std::endl;
                break;
        case Savings:
                os << "Savings" << std::endl;
                break;
        case CreditCard:
                os << "CreditCard" << std::endl;
                break;
        case InstantAccess:
                os << "InstantAccess" << std::endl;
                break;
        default:
                os << "Unknown" << std::endl;
        }
        os << std::endl;
        return os;
}

int main()
{
        customerInfo c1 = { "Carol", "Burns", 434.04, Checking };
        customerInfo c2 = { "Brandon", "Jay", 0.01, Checking };
        save(std::cout, c1);
        save(std::cout, c2);

        std::ofstream ofs("CutomerInfo.txt");
        save(ofs, c1);
        save(ofs, c2);

        return 0;
}
Topic archived. No new replies allowed.