# Suppose the numbers ($10,000, 6 percent, $500) were user selectable. Are there values for which the algorithm you developed would not terminate? If so, change the algorithm to make sure it always terminates

### All Answers

total answers (1)

total answers (1)

need an explanation for this answer? contact us directly to get an explanation for this answerYes, any interest rate that causes more money to be added each month than was taken out would prevent the solution to R1.12 from terminating. We can guarantee that our algorithm terminates by checking for this condition before the calculation starts:balance = $10,000monthly interest rate = 0.5%monthly withdrawal amount = $500if balance * monthly interest rate > monthly withdrawal amountreport that the balance will never reach zeroelsetotal months = 0while balance is greater than $0increase balance by 0.5% of its valuedecrease balance by $500add 1 to the total number of monthsyears to deplete = total months /12