Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 9 Online
OpenStudy (anonymous):

PS1 Q2 -- My code seems to work for the first case it gets the minimum monthly payment and required months correct, however it fails to find the correct balance. In the second test case with an outstanding balance of 32000 and an interest rate of .2 it fails to find the correct minimum payment and the balance. Where is my code failing, I can't seem to find the error so I was hoping a fresh set of eyes would be able to locate it.

OpenStudy (anonymous):

My code is attached.

OpenStudy (e.mccormick):

For one, you are doing your interest wrong. You found the interest on the first month, but you are not adjusting it for payments and compounding. I ran your program, then did a standard actuarial table in a spreadsheet and it did not match up, so I ran it on a loan calculator and again it does not match up. .2 interest is huge. That is 20%. Not sure if that is adding to your problems or not, but I would fix the compounding problem first. Or is this supposed to be simple interest only?

OpenStudy (e.mccormick):

Well, if it was simple interest only, it would not be calculated that way.

OpenStudy (e.mccormick):

Try this with your target loan and see if you get the same payment ammount for a smaller loan with less interest. If not, work on that first. Remember, monthy interest is computed and added each month. Also, you are doing your months wrong. You are doing month 0 to 12. That is 13 numbers. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12. If you start at 1, you can do 1 to 12 and have it be 12.

OpenStudy (anonymous):

Thanks so much for you answer. It is compounding interest so I think that is where the problem lies. I'll work on fixing that and the months.

OpenStudy (anonymous):

I fixed it thank you so much. I really new to solving problems with programming, thanks alot.

OpenStudy (e.mccormick):

np. Programming is, by and large, about breaking big problems into lots of small problems.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!