Hello,
I want to write an equation to find the average speed:
float average_speed;
int pulseleft, pulseright;
average_speed = (pulseleft + pulseright) / 2;
But i want to retain the float value after division and not round it up/down.
Will dividing by 2.0 fix this? I have no idea why this would even work, but i saw it in some code online during my research.
average_speed = (pulseleft + pulseright) / 2.0;
Or should i use casting, like the following:
average_speed = (float)(pulseleft + pulseright) / 2;
Or should i combine casting and divide by 2.0?
average_speed = (float)(pulseleft + pulseright) / 2.0;
I'm confused.