Can't get this to work right

at the end when I type the account number I want to view it only works for the first account number entered. Also when I display the account numbers some have a decimal point. Maybe I need to go about it in a whole new way. I'm not sure...

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
#include <iostream>// for cout, endl
#include <iomanip>// for setw() and setprecision()

using namespace std;// "just do it"

struct BankAccount
{
	int input;
	double accountInfo[5][6];
	double balance;
	double viewAccount;
};

int main ()
{
	int input = 0;
	double balance = 0;
	double viewAccount = 0;
	double accountInfo[5][6] = { {-1, -1, -1, -1, -1, -1},
		                         {-1, -1, -1, -1, -1, -1},
								 {-1, -1, -1, -1, -1, -1},
								 {-1, -1, -1, -1, -1, -1},
	                             {-1, -1, -1, -1, -1, -1}, };

	BankAccount AccountInfo;

//	cout ;//set number of decimal places


	// get account numbers from user
	for (int index1 = 0; index1 < 5; index1 ++)
	{
		int count = 0;
		
		// get account number from the user
		while (accountInfo[index1][count] == 0 || accountInfo[index1][count] < 1000 || accountInfo[index1][count] > 9999)
		{
			cout << "Enter account number for account #" << 1 + index1 <<" ." << endl;
			cout << "The account number should be between 1000 and 9999" << endl;
			cout << "and can not be the same as any other account number. ";
			cin >> AccountInfo.accountInfo[index1][count];
			accountInfo[index1][count] = AccountInfo.accountInfo[index1][count];
			cout << endl;
			
			for (int index2 = index1; index2 >= 0; index2 --)
			{
				if (accountInfo[index2][0] == accountInfo[index1][count] && index1 != index2)
				{
					accountInfo[index1][count] = 0;
				}// end if

			}// end for
		}// end while

		count = count ++;

		// get account balances from user
		while (accountInfo[index1][count] < 0 || accountInfo[index1][count] > 100000)
		{
			cout << "Enter the beginning balance for account #" << 1 + index1 <<" ." << endl;
			cout << "The beginning balance must be between $0 and $100,000 ";
			cin >> AccountInfo.accountInfo[index1][count];
			accountInfo[index1][count] = AccountInfo.accountInfo[index1][count];
			cout << endl;// blank line
		}// end while

		count = count ++;

		// get interest rate from user
		while (accountInfo[index1][count] < 0 || accountInfo[index1][count] > 0.15)
		{
			cout << "Enter the interest for the first account #" << 1 + index1 <<" ." << endl;
			cout << "The interest rate must be between 0% and 0.15% ";
			cin >> AccountInfo.accountInfo[index1][count];
			accountInfo[index1][count] = AccountInfo.accountInfo[index1][count];
			cout << endl;// blank line
		}// end while

		count = count ++;

		//gett account term from the user
		while (accountInfo[index1][count] < 1 || accountInfo[index1][count] > 10)
		{
			cout << "Enter the term for account #" << 1 + index1 <<" in years." << endl;
			cout << "The term must be between 1 and 10 years. ";
			cin >> AccountInfo.accountInfo[index1][count];
			accountInfo[index1][count] = AccountInfo.accountInfo[index1][count];
			cout << endl;// blank line
		}// end while

		count = count ++;

		// get automatic deposit ammount
		while (accountInfo[index1][count] <= 0)
		{
			cout << "Enter the ammount automaticly deposited each month in to account #" << 1 + index1 <<". ";
			cin >> AccountInfo.accountInfo[index1][count];
			accountInfo[index1][count] = AccountInfo.accountInfo[index1][count];
			cout << endl;// blank line
		}// end while

		count = count ++;

		// get automatic withdrawal ammount
		while (accountInfo[index1][count] <= 0)
		{
			cout << "Enter the automatic withdrawal ammount each month for account #" << 1 + index1 <<". ";
			cin >> AccountInfo.accountInfo[index1][count];
			accountInfo[index1][count] = AccountInfo.accountInfo[index1][count];
			cout << endl;// blank line
		}// end while

	}// end outer for loop



	// output to the screen
	for (int index1 = 0; index1 < 5; index1 ++)
	{
		cout << "Account Number" << endl;
		cout << AccountInfo.accountInfo[index1][0] << fixed << setprecision(0) << endl;
		cout << "Strating Ballance" << endl;
		cout << AccountInfo.accountInfo[index1][1] << setprecision(2) << endl;
		cout << "Interes Rate" << endl;
		cout << AccountInfo.accountInfo[index1][2] << setprecision(2) << endl;
		cout << "Account Term" << endl;
		cout << AccountInfo.accountInfo[index1][3] << setprecision(2) << endl;
		cout << "Deposit Ammount" << endl;
		cout << AccountInfo.accountInfo[index1][4] << setprecision(2) << endl;
		cout << "Withdrawal Ammount" << endl;
		cout << AccountInfo.accountInfo[index1][5] << setprecision(2) << endl;
		cout << endl; // blank line
	}// end for

	cout << "The combined balance for all five accounts is $";

	//balance = AccountInfo.balance;
	
	for (int index1 = 0; index1 < 5; index1 ++)
	{
		balance = balance + AccountInfo.accountInfo[index1][1];
	}// end for

	cout << balance << fixed << setprecision(2) << endl;
	cout << "The average balance for all five accounts is $" << balance / 5 << endl;
	cout << endl; // for blank line

	viewAccount = AccountInfo.viewAccount;

	// display user requested account info
	while (viewAccount == 0 || viewAccount == 1 || viewAccount != 12345)
	{
		if (viewAccount == 1)
		{
			cout << "Account number not found. Please try again!" << endl;
		}

		cout << "Please enter the number for the account you would like to view." << endl;
		cout << "Or enter 12345 to quit. ";
		cin >> AccountInfo.viewAccount;
		viewAccount = AccountInfo.viewAccount;
		cout << endl;

		for (int index1 = 0; index1 < 5; index1 ++)
		{
			if (viewAccount != 12345)
			{
				if (viewAccount == accountInfo[index1][0])
				{
					cout << "Account Number" << endl;
					cout << AccountInfo.accountInfo[index1][0] << fixed << setprecision(0) << endl;
					cout << "Strating Ballance" << endl;
					cout << AccountInfo.accountInfo[index1][1] << setprecision(2) << endl;
					cout << "Interes Rate" << endl;
					cout << AccountInfo.accountInfo[index1][2] << setprecision(2) << endl;
					cout << "Account Term" << endl;
					cout << AccountInfo.accountInfo[index1][3] << setprecision(2) << endl;
					cout << "Deposit Ammount" << endl;
					cout << AccountInfo.accountInfo[index1][4] << setprecision(2) << endl;
					cout << "Withdrawal Ammount" << endl;
					cout << AccountInfo.accountInfo[index1][5] << setprecision(2) << endl;
					cout << endl; // blank line
				}// end inner if
				else
				{
					viewAccount = 1;
				}// end else
			}// end outer if
		}// end for
	}// end while

	cout << "Thank you for visiting Parkville Bank." << endl << endl;

	return 0;

}// end main 
Last edited on
So no help on either one of these problems?
I will give you some general help when things like your problems happen.
Debug your code. Not the kind where you go manually looking for problems. But step through your code with your compiler to see exactly what happens as you meander through your program.
Thanks for the suggestion... I'll give that a try. This is for an online class so there’s not much help from the instructor.
No problem, if you still can't figure it out, post again and I'll be glad to help.
There's too much going on in a single function. So I'd suggest that you separate it into several functions. You should have a closer look to those similar loops. You might even reduce code.

A function should not be larger than the screen.
I agree that it is large. But the instructions were "Write a main function that..." so I wrote it all in the main. I think the next assignment splits it up.
Topic archived. No new replies allowed.