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

Problem Set 1 B: That's what I've done so far, but my program is stuck everytime in a loop: http://dpaste.com/1539469/

OpenStudy (anonymous):

I think the problem with the code is that the while loop is dependent on the balance being >=0. The rest of your code dictates that this will always be the case, so you need to find another way to loop - or perhaps just switch to an if-block.

OpenStudy (anonymous):

It seems to me that balanceA would always be positive if you start off with balance > MonthlyPayment, i.e. balance > 10. What you're doing is multiply balance by a factor > 1, and then subtracting 10 from it, and storing the result in balanceA. If balance is more than 10, balanceA would be positive, and then you add balanceA to balance at the end of each iteration in the for-loop, so basically, balance keeps increasing, and hence, you never exit the while loop. I suggest you do a print somewhere inside the for loop to see how your balance value is changing and you should notice it increasing all the time. Hope that helps!

OpenStudy (anonymous):

If the monthly payment is low enough, then it will take forever before the balance gets paid off.

OpenStudy (anonymous):

^^^ The balance is increasing because of your += assignment of balance, this is the first 12 months 100.0 191.5 375.8725 747.3830875 1495.97692131 3004.39349644 6043.85289534 12168.3635841 24509.252622 49376.1440333 99482.930227 200448.104407 403892.930381 the assignment should just be an equals sign. get rid of the else statement. Make it revolve around balanceA rather than balance (reset balanceA to balance) Those are a few of my pointers

OpenStudy (anonymous):

Yeah, you can either change: `balanceA = balance*(1+interest) - MonthlyPayment` to `balanceA = balance*interest - MonthlyPayment` Or change `balance += balanceA` to `balance = balanceA`

OpenStudy (anonymous):

Thanks all, I made it

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!