C++ int float casting

后端 未结 8 1549

Why is m always = 0? The x and y members of someClass are integers.

float getSlope(someClass a, someClass b)
{           
    float m = (a.y - b.y) / (a.x -         


        
8条回答
  •  天命终不由人
    2020-12-09 08:24

    he does an integer divide, which means 3 / 4 = 0. cast one of the brackets to float

     (float)(a.y - b.y) / (a.x - b.x);
    

提交回复
热议问题