int to float back to in

I swear this has worked for me before, and I can't believe I am having so much trouble with this.

int middlespacing=floor((position[n - count +1] - position[0])/position[n-count]);

Everything is an integer. Since the result needs to be floored anyway, I would prefer to keep it as an integer. However on dividing I get 0.

I have tried This with no luck:

int middlespacing=floor(((float)position[n - count +1] - (float)position[0])/(float)position[n-count]);

Can anybody help me out with this.
can you tell us the values in the position array? At least the 3 of interest.
closed account (zb0S216C)
"floor( )" only accepts floating-point input, and output. When you assign a floating-point value to an integral variable, the number on the right-hand side of the decimal place is truncated, leaving you with a whole number. Here's an example:

int X(100.10f); // the ".10" is removed, leaving "100" behind. 


I actually just figured it out but here you go


position[n-count+1] = 2340
position[0] = 1852

It was a simple math error. not an issue of data types. At that point in the code position[n-count] //3 didn't even have a value so I was effectively dividing by zero.

the correct line should have read.

int middlespacing=floor((position[n - count +1] - position[0])/(n-count+1));

Thanks anyway.
Topic archived. No new replies allowed.