How to output final balance for checkbook program

Hello,

This program is for a class assignment. I know the rules say that you won't tell me exactly what to do, but hints would be helpful, too. I am very new at this. This is the third C++ assignment I have worked on.

The assignment is to create a checkbook program. This is what I have so far

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
#include <iostream>
using namespace std;

int AddBal ( int a, int b) //postive integer - deposit
{
	int result = a + b;
	return result;
}

int SubBal ( int a, int c) //negative integer - withdrawal
{
	int result = a - c;
	return result;
}

int FinBal () // Final checkbook balance
{
	int resutlt = 

int main ()
{
	int OpenBal;
	cout << "Enter opening balance: ";
	cin >> OpenBal;

	int withdep;
	cout << "Enter withdrawals and deposits: ";
loop:
	cin >> withdep;

	if ( withdep > 0)//if input is positive
	{
		AddBal (OpenBal, withdep); //add it to opening balance
		goto loop;
	}
	else if ( withdep < 0 )//if input is negative
	{
		SubBal (OpenBal, withdep);//subtract it from opening balance
		goto loop;
	}
	else if ( withdep == 0)
	{
		cout >> "The final balance is " >> FinBal >> endl; //output final balance
	}
}


Obviously, this is not executable. I'm trying to figure out how to make the program output the final balance after multiple deposits and withdrawals have been put in. The program doesn't seem to be doing the calculations, either. Any help you can give me would be deeply appreciated.
I will take a look at this and see if I can get it to work and then I can give you some tips. I myself am learning about C++ but I have done quite a few assignments so far.

I have never worked with "goto", so I can't help you there, but three things I did notice were:

1. Missing an end bracket in your FinBal().

2. I think your main() needs a return, such as "return 0;", as your last line within the main().

3. Give your user the exit key to get them out of the program loop. Maybe add the line:

cout << "Press 0 to get your Final Balance";

Good luck!

Last edited on
I know what all fixes you need, but I am too tired to type a long post to fix your incorrect/incomplet code. :(
I also wanted to note that you should verify that your "cout and cin" arrows are pointing in the correct directions.

I do not see a purpose for the "SubBal" function/method. If you were to actually send a negative number to it, it would add it instead of subtract because you would have a ( 10 - (-5) ) situation. If you send the "withdep" to your AddBal(), it will do the same thing regardless of the sign.

For example,

Let's say you entered 10 as your opening balance.

Then you had a deposit of 5.

Your AddBal() would go:

10 + 5 = 15
return 15;


Now, let's say you entered 10 as your opening balance.

Then you had a withdrawal of -5.

Your AddBal() would still go:

10 + (-5) = 5
return 5;


you would just need to change your IF statement to reflect the change, something like:

if ( withdep != 0 ) // if withdep does NOT equal zero
{
AddBal (OpenBal, withdep);
goto loop;
}

else
{
cout << "The final balance is " << FinBal << endl; //output final balance
}



Just some ideas to go with your assignment.

Using goto is not a good idea. Use loops, a while or do-while loop will solve your purpose.
Any luck with your program so far? It has been a few days and I wonder if you have it done?

Can I help any further?


Graphitea
Using goto is not a good idea. Use loops, a while or do-while loop will solve your purpose


A while loop should help a good bit.

cout << "Press 0 to get your Final Balance";


A good Idea, but DON"T use "system()" anything. If you want to use cin.ignore();, than go ahead.


Topic archived. No new replies allowed.