Need some help...I have a program I'm writing that is supposed to calculate the amount left on the loan. I've tried to use a do-while loop to get this done and I'm having a few issues. Can someone help me down the right path here? I know you would need to add the months starting at one. I'm having a hard time getting the amount of the loan to go down by the payment applied. I thought about calling a function, but I couldn't get that to work either. Not looking for the answer...just a nudge in the right direction. Thanks.
int main ()
{
int month = 1;
int loanamount, payment, loan;
cout << "Please enter the amount of the loan: ";
cin >> loanamount;
cout << "Please enter the amount of the payment each month: ";
cin >> payment;
loan = loanamount-payment
do
{
cout << "Month " << month++ << " balance is " << loan << " after the payment" << endl;
}
while (loan >=1 )
cout << "The last payment is " << payment << endl;
Makes sense in theory...but when I move it into the loop..it only subtracts it once while the months keep adding up. I've fixed all of the syntax issues and the program executes...the only issue is that the payment is not being subtracted each time the loop is run. Do I need an if-else statement in there somewhere?
EX: cin loanamount...
in the do loop...loanamount = loanamount - payment...
What's the purpose of the last line? It just tells the user exactly what he already knows his last payment is going to be since all payments are the same amount.
Yep...my bad on the month thing. Looks like I'm making progress...I'll post the final code here in a bit if I can get it figured out. Thanks again.
BTW...the last line is supposed to say your last payment is whatever is left. So...say your loan balance is $1500 and you pay $140 each time. For your last payment, your balance is only $100, so instead of paying $140, you would pay $100 to pay off the loan. Make sense?
int main ()
{
int month = 1;
int loanamount, payment;
cout << "Please enter the amount of the loan: ";
cin >> loanamount;
cout << "Please enter the amount of the payment each month: ";
cin >> payment;
do
{
loanamount = loanamount - payment;
cout << "Month " << month++ << " balance is " << loanamount << " after the payment" << endl;
}
while (loanamount >= payment);
cout << "The last payment is " << loanamount << endl;
Here is the final code. Thanks for your help All. I placed an "if" statement at the end because I just want the program to end if the ending balance is $0. Appreciate the inputs...huge help.
BTW...still new to this site. How do I have code displayed as the above? Right now I am just doing copy and paste (you can probably tell - :)).
int main ()
{
int month = 1;
int loanamount, payment;
cout << "Please enter the amount of the loan: ";
cin >> loanamount;
cout << "Please enter the amount of the payment each month: ";
cin >> payment;
do
{
loanamount = loanamount-payment;
cout << "Month " << month++ << " balance is $" << loanamount << " after the payment" << endl;
}
while (loanamount >= payment);
if (loanamount > 0)
{
cout << "The last payment is $" << loanamount << endl;
}
}