C++ int float casting
Integer division occurs, then the result, which is an integer, is assigned as a float. If the result is less than 1 then it ends up as 0.
You'll want to cast the expressions to floats first before dividing, e.g.
float m = static_cast<float>(a.y - b.y) / static_cast<float>(a.x - b.x);
You need to use cast. I see the other answers, and they will really work, but as the tag is C++
I'd suggest you to use static_cast
:
float m = static_cast< float >( a.y - b.y ) / static_cast< float >( a.x - b.x );