0
Need help in outputting the float version of this.
4 Respuestas
+ 5
In the expression "50 * 5 / 100", as the precedence of multiplicatikn and division is the same, "50 * 5" is evaluated first. So the resulting expression is
(50 * 5) / 100
= 250 / 100
= 2 (as integer division takes place)
Changing any of the 3 numbers to float will fix the issue and give the correct result.
50.0f * 5 /100
50 * 5.0f / 100
50 * 5 / 100.0
50.0f * 5.0f / 100.0
and so on, will all give the correct result
+ 2
Thank you XXX
It worked
0
Hi RockStar
C++ automaticly rounds. Check this for methods to fix it:
https://stackoverflow.com/questions/33854825/stdcout-with-floating-number
0
Ollie Q Olathe stack gave me a lot that I think I have to learn about that because I tried "std::cout << 5 * 5 / 100 << std::endl; but didn't work