Program working wrong for big values

  • Thread starter Thread starter preceptor1919
  • Start date Start date
  • Tags Tags
    Program
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
8 replies · 1K views
preceptor1919
Messages
35
Reaction score
0
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.
 
Physics news on Phys.org
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
 
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?
 
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;
}
 
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
 
preceptor1919 said:
I don't know what happened with 100,000

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
 
Yah I also saw my mistake there haha thank you.
 
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?