Why is this variable never true?

I am testing a latitude/longitude point against a bounding box, to determine if the point is inside of it or not. I am lost as to why the variable inBounds is never set to 1. Since the entire piece of code is complicated, I had the program print out the variables in their current state right before the test. Here are the variables:

fltLatitude 48.2728
fltLongitude -122.772

SITE_LON_EAST[x] =  117.88
SITE_LON_WEST[x] =  125
SITE_LAT_SOUTH[x] = 46.24
SITE_LAT_NORTH[x] =  49.39

And this is the code that executes immediately after:

if(fltLongitude>SITE_LON_EAST[x] && fltLongitude<SITE_LON_WEST[x] && fltLatitude>SITE_LAT_SOUTH[x] && fltLatitude<SITE_LAT_NORTH[x]) // All must be true
{
    inBounds=1;
}
        
if(inBounds==0)
{
    cout << "Point is out of bounds " << endl;  
}
if(inBounds==1)
{
    cout << "Point is in bounds." << endl;
}

Why is inBounds never set to 1?

>Solution :

Because fltLongitude (-122.772) is not greater than SITE_LON_EAST[x] (117.88), then the first check fltLongitude>SITE_LON_EAST[x] is false, which makes the whole set of && conditions false, then inBounds=1; never happens.

Leave a Reply