int to float back to in
Sep 25, 2012 at 2:38pm UTC
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)/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)/( float)position[n-count]);
Can anybody help me out with this.
Sep 25, 2012 at 2:58pm UTC
can you tell us the values in the position array? At least the 3 of interest.
Sep 25, 2012 at 3:03pm UTC
" 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.
Sep 25, 2012 at 3:13pm UTC
I actually just figured it out but here you go
position[n-count+1] = 2340
position = 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)/(n-count+1));
Topic archived. No new replies allowed.