Using two arrays

I'm working on a problem to balance a checkbook. I've been struggling with it so I split it up into its components. I first made an array to store withdrawals. When I ran this program, everything ran fine. Now I'm trying to create a second array to store deposits. I can't get it to display properly.

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
//checkbookagain.cpp

#include <iostream>
using namespace std;

int main ()
{
	double with = 0;
	double dep = 0;

	cout << "How many withdrawals were made? ";
	cin >> with;
	cout << "How many deposits were made? ";
	cin >> dep;

	double *wAmt = new double[with];
	double *dAmt = new double[dep];

	for (int i=0; i<with; i++)
	{
		cout << "Enter in the amount of withdrawal " << i + 1 << ": $";
		cin >> wAmt[i];
	}// end for


	for (int j=0; i<dep; j++)
	{
		cout << "Enter in the amount of deposit " << j + 1 << ": $";
		cin >> dAmt[j];
	}//end for

	for (i=0; i<with; i++)
	{
		cout << "Withdrawal " << i + 1 << ": $";
		cout << wAmt[i] << endl;
	}//end for

	for (j=0; j<dep; j++)
	{
		cout << "Deposit " << j+1 << ": $";
		cout << dAmt[j] << endl;
	}//end for

	return 0;
}//end of main function 


When its this way, it lets me input everything up to the deposits. When it gets to the deposit input, it just displays some numbers in scientific notation and I'm not sure why.
First off it doesnt look like you are using a IDE cause when i copyed and pastes your code i got a few compiler errors for in lines 8 and 9 your code is:
1
2
double with = 0;
	double dep = 0;

now the problem is not that you declared then double but that you ask for a whole number question...what if user entered 2.5....YOU CAN'T HAVE HALF AN ARRAY. so those need to be int.

Also your problem is on line 26
for (int j=0; i<dep; j++)
now first off the declared variable in this loop is j but your checker is i?and to further the destruction your last loop is
for (int i=0; i<with; i++)
so if i had to guess when you run it is using the last i but you cant use the i in THAT scope.

And also you need to use the delete keyword to delete the memory you allocated in new.....so write
1
2
delete wAmt[];
delete dAmt[];


Im sorry if i was mean but i just told it how it was...also some advice would be to get you a compiler....it makes things 100 times easier!

Hope this helps
Thank you so much! That helped. My only problem is .. when I compile it I get 0 errors so I'm not sure if that's bad since you say you got 8? Also.. where do I insert the

1
2
delete wAmt[];
delte dAmt[];


I tried putting it after the last loop, but it gave me a compiling error. The error was:
error c2059: syntax error : ']'
Okay well I have this program about done, but I am reaching one final roadblock.

I need to display the beginning balance, the ending balance AND the balance after each deposit/withdrawal.

I have the beginning balance and ending balance, but I'm not sure what approach to take for the balance after each transaction.

Right now, I did this:

1
2
3
4
5
6
double *newBala = new double[with];
...
for (i=0; i<with; i++)
	{
	newBala[i] = begBal - wAmt[i];
	}//end for  


The problem with this is that for each transaction it only shows the beginning balance minus the withdrawal.. not minus the cumulative total of the withdrawals (and same situation for the deposits). How do I get the withdrawals to change the balance after each transaction?
Topic archived. No new replies allowed.