Click to See Complete Forum and Search --> : Need help with C++ loan payoff program


novi1
June 28th, 2006, 11:55 AM
I need help with an assignment please. The problem is simple but I'm having difficulty with boolean expressions and how to properly write the functions for this problem:
You have just purchase a stereo system that cost $1000 on the following credit plan. An interest rate of 18% per year(1.5% per month) and monthly payments of 50$.
I really need someone to help and walk me through a program that will tell how many months it will take to pay off the loan as well as the total amount of interest paid over the life of the loan.
I can't even figure out what kind of loop to use. The program does not need to be perfect but I need to show some effort and understanding of the program. Any help will be appreciated. Thanks.

ThermoSight
June 29th, 2006, 10:33 PM
I didn't have a clue as to how to calculate a loan payment so I just googled on "loan amortization" and found numerous calculators, and one site, the University of UT, gave the equation to do that.

The following code uses those equations, and provides results very similar to those provided by several online loan amortization calculators. It may not be the most elegant solution, but it provides pretty good results although you will almost certainly want to reformat the results.

void Form1::Quickie(void) {

float principal = 1000.;
float payment = 50.;
float apr = .18;
float mpr = apr/12;


float payments;
float totalPaid;
float totalInterest;

payments = Math::Log(payment / (payment - mpr * principal)) / Math::Log(1.0 + mpr);
totalPaid = payments * payment;
totalInterest = totalPaid - principal;

MessageBox::Show(String::Concat(payments.ToString(), S" payments\r\n",
totalPaid.ToString(), S" paid\r\ntotal interest: ",
totalInterest.ToString()),
S"Loan disclosure",
MessageBoxButtons::OK,
MessageBoxIcon::Hand);

} // end function 'Quickie'