Back to General discussions forum
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.
forgot to mention that in the above code ; S , R are doubles
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 !
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