tags:

views:

79

answers:

3

Write a program that lets the user enter the loan amount and loan amount period in number of years and displays the monthly and total payments for each interest rate starting from 5% to 8%, with an increment of 1/8.

I have now clue how to do this and would be delighted if someone would explain it better than the book does and dumb it down for me.

+1  A: 
for( interestrate=0.05; interestrate<=0.08; interestrate+=(0.01/8) )
  print_results( interestrate, amount, period )

void print_results( double interestrate, double amount, double period )
{
  total = calc_total( interestrate, amount, period );
  month = calc_month( interestrate, amount, period );
  fprintf( stdout, "total=%ld monthly=%ld for rate=%ld\n", total, month, interestrate );
}

double calc_total( double interestrate, double amount, double period )
{
  return // the result of the calulation
}

double calc_month( double interestrate, double amount, double period )
{
  return // the result of the calculation
}

Update:

Period might be an enum, depending on how you want to do this.

The next part is the calculation. Firstly, do they mean for the total to be a sum of the monthlies, or a single, non-compound rate? If the former, then calculating the total means adding up the monthlies, not its own function above. As for the monthlies:

Compound interest on a daily basis, would for a month mean calculating the interest for one day, adding the value onto the amount you own, and calculating the next day based on that amount, and so on, for a month. I believe that most places allow rounding to 30 days for a month, but check the requirements. Repeat for 30 iterations and you have the result. If you want just the interest earned, take out the original amount.

If compound interest is monthly, then for a month, it's just one iteration. Sometimes there's weekly, or even hourly interest periods. You'll have to format that for yourself.

Hope this helps.

eruciform
A: 

I think may be you can start from here. The PMT() formular is implemented in excel as well FYI.

http://en.wikipedia.org/wiki/Mortgage_calculator

airmanx86
A: 

You problem is basically dealing with compounding interest. It is done with a generally simple formula but since it's been a while since I dealt with it Ill refer you to this site for the formulas.

http://math.about.com/library/weekly/aa042002a.htm

Now there is a bit of an annoyance that I find with this assignment but I'll do my best despite. The thing with compounding interest it that it happens periodically (usually monthly as I think is your case but sometimes it can be annually, quarterly or biweekly) and it applies the interest to the amount at that time. So for example if you have $1000 compounded monthly at 10% after one month you will have $1100 but after 2 months you would have $1210 since the interest gets applied to the other interest and 10% of 1100 is 110 and not 100.

The problem is that I'm not sure how to factor actual monthly payments into the mix and couldn't find anything about it online. so I will do it the stupid way and omit the payments in the calculation. I know its not entirely correct but it should put you on the write track.

  • First get the get the amount of the principal balance and the period from the user.
  • Next convert the years into months.
  • Now you will have a for loop that goes from 5 to 8 with 1/8 increases. These will be the values that you will use for interest in each iteration.
  • apply the monthly compounding formula for you period to get your total payment and divide it by the number of months for monthly payment in each iteration of the loop to get the payments for that interest rate.

Here is a site that I think explains how to factor in the payments in the calculation but I haven't read the whole thing so I'm not sure.

http://mathforum.org/dr/math/faq/faq.interest.html

If it's not helpfull do this google search and work from there:

compound interest payment formula