Can anyone tell me why the calculations on lines 9 and 11, which seem to be identical, produce two different outputs. I know the difference isn\'t that great, but I am using the
This is an instance of GCC's most common non bug
That's how float behaves. Because of rounding error you don't get an exact result. It is extremely close to 410 for example 409.99999923
. However, if you print it as a float, by default c++ round to 6 figures and thus gives you 410
. In the second time, you assign it to integer. In this case, c++ doesn't perform a rounding but a truncation. This is why 409.