# Error msg using %

I'm trying to compute the bearing between 2 GPS locations. Anyhow, when I use the below code, I get an error:

``````float GPS_B_lat = 00.000000;     // latitude_destination at GPS B (test)
float GPS_B_long = -52.000000;  // longitude_destination at GPS B (test)

// angle off ot True North from GPS_A to GPS_B

// Latitude conversion
int GPS_lat_integer = GPS.latitude/100; // get only integer part of lat
float GPS_lat_shifting = GPS.latitude - (GPS_lat_integer * 100);
float GPS_lat_decimal_conversion = (GPS_lat_shifting / 60);
float GPS_A_lat = GPS_lat_integer + GPS_lat_decimal_conversion;

// Longitude conversion
int GPS_long_integer = GPS.longitude/100; // get only integer part of long
float GPS_long_shifting = GPS.longitude - (GPS_long_integer * 100);
float GPS_long_decimal_conversion = (GPS_long_shifting / 60);
float GPS_A_long = (-1)*(GPS_long_integer + GPS_long_decimal_conversion);

GPS_heading = (180 / M_PI) * (atan2(sin(GPS_B_long - GPS_A_long)*cos(GPS_B_lat), cos(GPS_A_lat)*sin(GPS_B_lat) - sin(GPS_A_lat)*cos(GPS_B_lat)*cos(GPS_B_long - GPS_A_long)));

``````

The error says:

" invalid operands of type 'float' and 'int' to binary 'operator%' " " In function 'void GPS_output()': " " error: invalid operands of types 'float' and 'int' to binary 'operator% '

If were were to remove the last line, my code runs. It's something about using the " % " in there.

Any ideas?

Both operands of % must be integer. You could use:

``````((int)GPS_heading + 360) % 360;
``````

Pete

For accuracy, you can do something like this instead:

``````GPS_heading = fmod( GPS_heading, 360.0 );

if ( GPS_heading < 0 )