Problem Set 1 - Problem 2.... having a difficult time wrapping my head around a portion of the code for Problem 2. Looking at the answer key(shameless), there seems to be two statements (one outside the while loop, one within the initial while loop) -- balance = initialbalance just curious as to why that statement is necessary within the while loop...I know that removing it from the while loop creates incorrect final results. Any help would be great!
Here is my attached code
You need to find the monthly payment that, for a given APR and initial balance, will give a total outstanding balance of 0 or less (i.e. the credit card is paid off). Thus, you start with balance=initialbalance. Then you check to see if the minimum_payment you are trying will pay off the balance in 12 months. So you go and perform that calculation. Then you go to outer while loop and check to see if balance is paid off. If not, you MUST reset the balance back to the initial payment. Otherwise you can't verify if the calculation you are performing will pay off the balance in a year as uyou are deducting from balance more than 12 times. Hope this helps.
I hope this flow chart helps. It's a rough outline but I *think* it's correct...
thanks so much, it is a bit clearer now, and diagrams are always useful...
Join our real-time social learning platform and learn together with your friends!