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
  • 301,070
  • 26
  • 186
  • 335
tmighty
  • 10,734
  • 21
  • 104
  • 218

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
  • 301,070
  • 26
  • 186
  • 335