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 | Science Articles, Homework Help, Discussion**

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!

**Physics Forums | Science Articles, Homework Help, Discussion**