# Program working wrong for big values

1. Sep 27, 2014

### preceptor1919

I am trying to figure out why my program gives wrong results or not execute for big values. I am trying to compute how long before a bank account is depleted if it has an interest and 500 is withdrawn from it monthly. If I use 100000, it gives a value of 526years, which I think is wrong. And if you put 150000. It takes so long for it to finish executing.

2. Sep 27, 2014

### gsal

Hhhmmm...well, if the interest is high enough so that the money generated in a month is greater than what you withdraw you will never finish the money

3. Sep 27, 2014

### preceptor1919

The interest is 6%

So if my program works fine for small valued like 500,10k and the likes,should it be just fine for big values?

4. Sep 27, 2014

### preceptor1919

Is it alright if I post the piece of my code that I use to extract how many months will pass?

while (iBalance >= 500){
iBalance = iBalance * interestMultiplier;//interestMultiplier = (1 + 0.06/12) Getting the amount added because of the interest rate

iBalance = iBalance - 500; //Withdraw 500 every month from the remaining balance

months += 1; //Increment 1 for each month's withdrawal
}

if (iBalance < 500 && !(iBalance == 0)){ //Last Withdrawal if balance is less than 500 but not 0
iBalance = iBalance - iBalance;

months+=1;
}

5. Sep 27, 2014

### Staff: Mentor

Try calculating the interest added as a separate variable. Then for each month display the interest, and the final balance for that month. That way you can see whether the numbers look reasonable.

6. Sep 27, 2014

### preceptor1919

wow thanks. It showed that it worked until 99,999. I don't know what happened with 100,000. It seemed liked nothing is being withdrawn from it. I'll look into it. Thankyou

7. Sep 27, 2014

### Staff: Mentor

The annual interest is 6% (0.06), so the monthly interest is 0.5% (0.005). Therefore, on a balance of 100,000, you get 500 in interest. Now you withdraw 500. What do you end up with? :D

8. Sep 27, 2014

### preceptor1919

Yah I also saw my mistake there haha thank you.

9. Sep 28, 2014

### voko

Just for the record, this problem has a mathematical solution. If $$\mathrm{initial \ amount} \ge {\mathrm{monthly \ withdrawal} \over \mathrm{monthly \ interest}},$$ you can withdraw infinitely. Can you show that?