Hello all. So i am trying to calculate the distance between two points on the earth's surface. Here is what I have:(adsbygoogle = window.adsbygoogle || []).push({});

Where tarListCode (Text):

//calculate distance here

dlat = abs(startLoc.lat - tarList[i].lat);

dlon = abs(startLoc.lon - tarList[i].lon);

a = pow(sin(dlat/2),2) + ( cos(startLoc.lat)*cos(tarList[i].lat)*pow(sin(dlon/2),2) );

c = 2*atan2(sqrt(a),sqrt(1-a));

tarList[i].distance = R * c;

and startLoc are the two locations.

Also, the program takes user input in the form of:

LATITUDEVALUE/(NorS) LONGITUDEVALUE(WorE) NAME

e.g: 2341/N 41355/W Random City

I have a part of the code that changes the sign of the latitude or longitude according to (N or S and W or E), here it is:

I am not getting errors but I am not achieving correct answers. Does anyone know what the problem may be? Thank you physics forums as usual!Code (Text):

//adjust sign of latitude according to N/S

if(tarList[i].noSo == 'N'){

tarList[i].lat = getLat(aString);

}else{

tarList[i].lat = -getLat(aString);

cout<<"MINUS USED!"<<endl;

}

//adjust sign of longitude according to W/E

if(tarList[i].weEa == 'E'){

tarList[i].lon = getLon(aString);

}else{

tarList[i].lon = -getLon(aString);

cout<<"MINUS USED!"<<endl;

}

**Physics Forums - The Fusion of Science and Community**

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Haversine formula C++ help!

Loading...

Similar Threads - Haversine formula help | Date |
---|---|

C/++/# Can you detect any formula here? | Oct 10, 2016 |

Bisection formula fortran90/95 | Jun 25, 2015 |

Problem with the Haversine Formula in C++! Help! | Dec 7, 2014 |

Formulas of the form (1+epsilon)-1 | Aug 16, 2013 |

Formula to fly up to a point at different speeds | Jun 21, 2012 |

**Physics Forums - The Fusion of Science and Community**