Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Program working wrong for big values

  1. Sep 27, 2014 #1
    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. jcsd
  3. Sep 27, 2014 #2
    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
     
  4. Sep 27, 2014 #3
    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?
     
  5. Sep 27, 2014 #4
    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;
    }
     
  6. Sep 27, 2014 #5

    jtbell

    User Avatar

    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.
     
  7. Sep 27, 2014 #6
    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
     
  8. Sep 27, 2014 #7

    jtbell

    User Avatar

    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
     
  9. Sep 27, 2014 #8
    Yah I also saw my mistake there haha thank you.
     
  10. Sep 28, 2014 #9
    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?
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Program working wrong for big values
  1. How do programs work? (Replies: 5)

Loading...