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
#include <iostream>
usingnamespace 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;
}
elseif ( withdep < 0 )//if input is negative
{
SubBal (OpenBal, withdep);//subtract it from opening balance
goto loop;
}
elseif ( 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:
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
}