Program working wrong for big values

  • Thread starter Thread starter preceptor1919
  • Start date Start date
  • Tags Tags
    Program
Click For Summary

Discussion Overview

The discussion revolves around a programming issue related to calculating the depletion time of a bank account with monthly withdrawals and interest. Participants explore the behavior of the program when handling large values, particularly focusing on the correctness of the results and execution time.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant reports that their program gives incorrect results for large values, specifically noting that a balance of 100,000 leads to unexpected execution behavior.
  • Another participant suggests that if the interest is sufficiently high, the account may never be depleted, as the interest generated could exceed the monthly withdrawal.
  • The interest rate is specified as 6%, leading to a monthly interest of 0.5%.
  • A participant shares a code snippet that attempts to calculate the number of months until the account balance is depleted.
  • One suggestion is made to calculate interest separately and display it alongside the balance for each month to verify the program's output.
  • A participant acknowledges a mistake in their understanding of the calculations when dealing with a balance of 100,000.
  • Another participant notes that there is a mathematical condition that indicates if the initial amount is greater than or equal to the monthly withdrawal divided by the monthly interest, the account can theoretically sustain withdrawals indefinitely.

Areas of Agreement / Disagreement

Participants express differing views on the behavior of the program with large values, and while some acknowledge mistakes in their calculations, there is no consensus on the overall correctness of the program's logic or the implications of the mathematical condition presented.

Contextual Notes

Participants discuss the limitations of the program when handling large values, particularly regarding the assumptions made about interest and withdrawals. There are unresolved questions about the execution time and correctness of the calculations for specific balances.

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.
 
Technology 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;
}
 
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.
 
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?
 

Similar threads

Replies
6
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 11 ·
Replies
11
Views
1K
Replies
11
Views
4K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 30 ·
2
Replies
30
Views
7K
  • Sticky
  • · Replies 13 ·
Replies
13
Views
8K
  • · Replies 5 ·
Replies
5
Views
2K
Replies
2
Views
3K