I must be doing something dumb:
float ans = (i/3);
So why when i = 7
is ans coming out at 2.0?
i
is an int
It's because the / operator is performing an integer division if both operands are integers. You could do this:
float ans = (i / 3.0f);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With