Q:

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

belongs to collection: Algorithm and pseudocode excersices

0

Write an algorithm to settle the following question: A bank account starts out with $10,000. Interest is compounded monthly at 6 percent per year (0.5 percent per month). Every month, $500 is withdrawn to meet college expenses. After how many years is the account depleted?

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

need an explanation for this answer? contact us directly to get an explanation for this answer

Yes, 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,000
monthly interest rate = 0.5%
monthly withdrawal amount = $500
if balance * monthly interest rate > monthly withdrawal amount
report that the balance will never reach zero
else
total months = 0
while balance is greater than $0
increase balance by 0.5% of its value
decrease balance by $500
add 1 to the total number of months
years to deplete = total months /12

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
In order to estimate the cost of painting a house,... >>
<< Write an algorithm to settle the following questio...