0

I'm running the following code:

float fSpeed = 1 + (uRate / 10);

uRate is -5.

I was hoping to get the result 0.5 because (uRate / 10) should be -0.5

However, fSpeed is 0. Does anybody see my mistake?

Thank you.

Vlad from Moscow
  • 265,791
  • 20
  • 170
  • 303
tmighty
  • 9,293
  • 20
  • 90
  • 192

1 Answers1

2

Just write

float fSpeed = 1 + (uRate / 10.0f);

In this case the expression (uRate / 10.0f) will have a floating value due to the usual arithmetic conversions.

Vlad from Moscow
  • 265,791
  • 20
  • 170
  • 303