Savings Calculator

Back to General discussions forum

sudo-Ilyria     2020-06-13 19:35:57

For Smaller inputs when the initial sum is 25 and Rate is 3 or 4 , the output just breaks . Please help with this . I tried rounding it down but same results .

while (S < R) { S = (S*(1+(P/100)) * 100) / 100; floor(S); timeCount++; } cout << timeCount << " ";

I am stuck on this for a week now . I am not sure what to do next.

sudo-Ilyria     2020-06-13 19:36:53

forgot to mention that in the above code ; S , R are doubles

sudo-Ilyria     2020-06-13 19:50:18

UPD I did it . It was simple enough but I still don't understand how .

What I did was after calculating S (which already multiplies and divides by 100 ) I again take floor((S * 100) / 100 ) which does the job . If anyone can explain why I need to do the multiply and divide by 100 2 times , it would be helpful !

deigumnov     2020-06-19 04:59:21
User avatar

Hello, I did the same string as floor((S * 100)/100) for make total S with cents, but as for me it looks like floor(S * 100)/100. Ex: S = 10.567, after S = floor(S * 100)/100, S = 10.56

Please login and solve 5 problems to be able to post at forum