Comparing floats to ints in C

Associate
Joined
24 Aug 2011
Posts
251
Location
Newcastle
Hi. This is literally making me go insane trying to get something working which seems really simple. Below is a snippet from some C code.

I am trying to test weather an integer is between two floats:

float x,y;
int startx=15;

if((x >=startx) && (x <= (startx+15)))
{
printf("It is in range\n");
}

So startx min and max values are 15 and 30, however I am getting values outside of these ranges. I think it must be a problem with floats.

Any Suggestions?
 
Back
Top Bottom