Bank Accounts program using structures.

I have an assignment to write a program using structures, getting input from a .txt file and output in text file as well. I have written a program that only reads and prints the data. I am trying to test if it works fine or not. I always comment an unnecessary code but still it wont compile. Now whats wrong with this program? Please help me i wont forget your kindness!

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
/* Bank Accounts Program */

#include <iostream>
#include <string>
#include <fstream>
#include <cstdlib>		//needed to use system() function
using namespace std;

const int MAX_NUM = 50;

void menu();
void read_accts(BankAccount, int &);
void findacct(const BankAccount account[], int num_accts);
void withdrawal(BankAccount account[], int num_accts);
void deposit(BankAccount account[], int num_accts);
void new_acct(BankAccount account[], int num_accts);
void close_acct(BankAccount account[], int num_accts);
void balance(const BankAccount account[], int num_accts);
void account_info(const BankAccount account[], int num_accts);
void print_accts(const BankAccount, int num_accts);


struct Name{

	string lastname;
	string firstname;
};

struct Account_info{
	
	char SSN;
	int acc_num;
	string acc_type;
	int acc_bal;	
};


struct BankAccount{
	Name name;
	Account_info acct_info;
};

int main(){

	BankAccount account[MAX_NUM];
	int num_accts;
	char choice;
	bool not_done = true;

	read_accts(account, num_accts);
	print_accts(account, num_accts);


	/* second part */
	/* prompts for a transaction and then */
	/* call functions to process the requested transaction */
	do {
		menu();
		cin >> choice;
		switch (choice)
		{
		case 'q':
		case 'Q':
			not_done = false;
			break;
		case 'b':
		case 'B':
			balance(account, num_accts);
			break;
		case 'd':
		case 'D':
			deposit(account, num_accts);
			break;
		case 'w':
		case 'W':
			withdrawal(account, num_accts);
			break;
		case 'n':
		case 'N':
			num_accts = new_acct(account, num_accts);
			break;
		case 'x':
		case 'X':
			num_accts = close_acct(account, num_accts);
			break;
		default:
			cout << "Error: '" << choice << "' is an invalid selection -  try again" << endl << endl;
			break;
		}

	} while (not_done);

	//  system("pause");
	return 0;
}

void menu()
{
	cout << endl << endl;
	cout << "Select one of the following transactions:" << endl;
	cout << "\t****************************" << endl;
	cout << "\t    List of Choices         " << endl;
	cout << "\t****************************" << endl;
	cout << "\t     W -- Withdrawal" << endl;
	cout << "\t     D -- Deposit" << endl;
	cout << "\t     N -- New Account" << endl;
	cout << "\t     B -- Balance Inquiry" << endl;
	cout << "\t     X -- Delete Account" << endl;
	cout << "\t     Q -- Quit" << endl;
	cout << endl << "\tEnter your selection: ";
	return;
}

void read_accts(BankAccount account[], int &count)
{
	// open input file
	ifstream dbfile("client_info_2.txt"); //comment-out for debugging
	//ifstream dbfile("con");                 //un-comment for debugging

	count = 0;                          //initialize count

	while (dbfile >> account[count].name.lastname)
	{
		dbfile >> account[count].name.firstname;
		dbfile >> account[count].acct_info.SSN;
		dbfile >> account[count].acct_info.acc_num;
		dbfile >> account[count].acct_info.acc_type;
		dbfile >> account[count].acct_info.acc_bal;
		count++;
	}

	dbfile.close();
	return;
}

void print_accts(const BankAccount account[], int num_accts)
{
	// open output file
	//  ofstream dbfile("c:\\bc\\cisc3110\\pgms\\chapter_07\\myoutput.txt"); //comment-out for debugging
	ofstream cfile("con");             //un-comment for debugging

	cfile.setf(ios::fixed, ios::floatfield);
	cfile.precision(2);                //set decimal precision

	cfile << "\t\tContestants in the Database\n\n";
	cfile << "Name\t\tSSN\tAccount #\tAccount Type\tAccount Balanace\tSalary\n\n";
	for (int count = 0; count < num_accts; count++)
	{
		cfile << account[count].name.lastname;
		cfile << "\t" << account[count].name.firstname;
		cfile << "\t" << account[count].acct_info.SSN;
		cfile << "\t" << account[count].acct_info.acc_num;
		cfile << "\t" << account[count].acct_info.acc_type;
		cfile << "\t" << account[count].acct_info.acc_bal;
		cfile << "\t";
		cfile.width(9);
		cfile << endl;
	}
	cfile.close();
	return;

};

void findacct(const BankAccount account [], int num_accts){
	
};


void withdrawal(BankAccount account [], int num_accts)
{
	return;
}
void deposit(BankAccount account [], int num_accts)
{
	return;
};
void new_acct(BankAccount account [], int num_accts)
{
	return;
};
void close_acct(BankAccount account [], int num_accts)
{
	return;
};
void balance(const BankAccount account [], int num_accts)
{
	return
};
void account_info(const BankAccount account [], int num_accts)
{
	return;
};


Last edited on
Either move your function declarations after your structure declarations or forward declare the structures before the function prototypes, otherwise the compiler won't know what a BankAccount is.
Topic archived. No new replies allowed.