In another Bruce Eckels exercise in calculating velocity, v = s / t where s and t are integers. How do I make it so the division cranks out a float?
v = s / t
Cast one of the integers to a float to force the operation to be done with floating point math. Otherwise integer math is always preferred. So:
v = (float)s / t;