#### Archived

This topic is now archived and is closed to further replies.

# using recursion to find mortgage?

This topic is 6209 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, I tried posting this in another forum and got in trouble I''m trying to find out how to find out how many years it would take to pay off $120,000 at$1250 a month with a interest rate of $8.25. Now i''m assuming I have to use some kind of recurion (is that what its even called?), but I''m not too sure how any help would be very appreciated, thanks,Scott #### Share this post ##### Link to post ##### Share on other sites Advertisement It doesn't nessisairly have to be recursive... something like this should work.. int principle = 120000; int months = 0; while (principle > 1250 ) { interest = principle * 0.0825; paymentAgainstPrinciple = 1250 - interest; principle -= paymentAgainstPrinciple; months++; } months ++; years = months / 12; Something like that should get you pretty close. Edited by - ironside on November 20, 2001 8:59:40 PM #### Share this post ##### Link to post ##### Share on other sites this is called "amortization"... there is a fairly simple formula for this, but i forget what it is... look it up in a search engine or something... --- krez (krezisback@aol.com) #### Share this post ##### Link to post ##### Share on other sites Here it is recursively! int Mortgage(double iPrinciple){ if (iPrinciple <= 0) return 0; return Mortgage(iPrinciple-(1250-(iPrinciple*0.0825)))+1;}  But the big problem is that the system stack (P2 350mhz, 64mbSDRAM) can''t handle it for 120,000 but it does work up to 14,000. I''m interested to see if there is a better way to do it recursively since that''s what i''m studying right now, next class is about binary trees! #### Share this post ##### Link to post ##### Share on other sites Hello, In your original post, you said the the interest is$8.25. Everyone that has replied has read it as 8.25%.

If it is 8.25% per month, then you will never pay off $120,000 at$1250 per month.

If it is \$8.25 per month, then you can use either approach, but change all the the  principle * 0.0825  to  principle + 8.25

I think that should work.

Later,
DarkMonkey

##### Share on other sites
Sorry DarkMonkey, it is 8.25% sorry my mistake.

I''m trying the following withouth luck, it works until principle hits around 15,000, then it doesn''t get any lower.

  int months = 0;double principle = 120000;double payment = 0;double interest = 0;while (principle > 1250 ){ interest = principle * 0.0825; payment = interest - 1250; principle -= payment; months++;}

thanks,
Scott

##### Share on other sites
I don''t know if this makes a difference however this is what the 8.25 is for my program:

annualRate = 8.25

Mortgage annual rate: is used to compute how much interest is to be paid to the financial institution each month. In Canada, the monthly interest rate (called the effective monthly rate) is computed in a rather strange way; for example, if the annual interest rate is 12.0%, a useable effective monthly rate would be the sixth root of one half this annual rate.

so does that mean 8.25% interest rate?

##### Share on other sites
quote:
Original post by hpox
Here it is recursively!

int Mortgage(double iPrinciple){	if (iPrinciple <= 0)		return 0;	return Mortgage(iPrinciple-(1250-(iPrinciple*0.0825)))+1;}

But the big problem is that the system stack (P2 350mhz, 64mbSDRAM) can''t handle it for 120,000 but it does work up to 14,000. I''m interested to see if there is a better way to do it recursively since that''s what i''m studying right now, next class is about binary trees!

I would say the better way is not to do it recursively - recursion is almost never the right approach, especially to the types of problems used to demonstrate how recursion works.

However, given that something is being done recursively, declaring scratch variables static and eliminating tail-recursion is usually the way to go. In your sample code there, there appears to be no variables or tail-recursion to eliminate. Can you adjust the stack size?

--

Get A Stripper on your desktop

##### Share on other sites
int months = 0;
double principle = 120000;
double payment = 0;
double interest = 0;
while (principle > 1250 )
{
interest = principle * 0.0825;
payment = interest - 1250;
principle -= payment;
months++;
}

i think the problem is that the interest - 1250 is incorrect.
the amount of interest your paying should allways be less then your monthly payment... some amount should be going towards your principle.

in essence it should be payment = 1250 - interest.

unfortunatly 8.25% of 120000 is 9900 something, wich you obviously can't pay in a monthly payment of 1250, wich makes me thing the mortgage lenders must be spreadding the interest out over the life of the loan a little.

it could be 8.25% calcuated annually, wich means you would have to pay 8.25% / 12 interest each month? and each month the principle would be a little less....? i'm just speculating at this point.

Edited by - ironside on November 21, 2001 2:19:51 AM

##### Share on other sites
I see there aren''t many mortgage-holders here. =)

Finance math scares the bejeezus out of me. I can do all sorts of spooky calculus, but those IRS forms give me nightmares. I''m not sure what the deal is.

Anyway, I''m sure the reason the original poster got in trouble was because this smells like a homework problem. But since I''m going to give you real-life answers, and real life has nothing to do with homework, I have a clear conscience.

When you get a mortgage you are locked down at a percentage, say 8.25%. You don''t get an infinite mortgage, you get an N-year mortgage. I have a 30-year mortgage. What they do is at the front-end, they calculate 8.25% interest over 30 years, and add the two together than that''s what your sum cost of the mortgage is. It''s usually a very big and frightening number you should try not to think about.

They then divide this number (total interest + loan amt) by the number of months you have to pay it off; this is your monthly P&I payment (Principle & Interest). In the first years of your loan, you are paying like 95% interest and 5% principle; this is actually handy because interest is tax-deductible. They use a scale as you go on so that by the end you''re paying 5% interest and 95% principle at the end. These numbers aren''t exact, but that''s the general idea.

In addition to your P&I you probably have an escrow, which is completely different from the escrow term used when you''re trying to buy the house. The escrow part of the mortgage bill is money they sock away if the mortgage company is paying your real estate taxes. Then there''s home owners association fees if you have one of those, and I think there might be something else in there but I don''t have my bill in front of me right now.

Probably doesn''t help solve the problem, but that''s how mortgages work (in real life).

1. 1
Rutin
67
2. 2
3. 3
4. 4
5. 5

• 21
• 10
• 33
• 20
• 9
• ### Forum Statistics

• Total Topics
633418
• Total Posts
3011785
• ### Who's Online (See full list)

There are no registered users currently online

×