title: great circle distance c++
body: <p>I've included code (now) for the great circle distance formula. Code works until one of the lats/longs has S/E attached as their respective directions ( I attempted to use S/E as "negative directions"). Any help is extremely appreciated!</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;math.h&gt;
  #include "lat.hpp"
  #include &lt;string&gt;
  
  #define PI 3.14159265
  
  
  double greatCircleDistance(double lat1, double long1, char latDir1 ,
                              char longDir1, double lat2, double long2,
                              char latDir2, char longDir2)
    {
    double dLat;
    double dLong;
  
     latDirectionCheck(latDir1, lat1);
     latDirectionCheck(latDir2, lat2);
     longDirectionCheck(longDir1, long1);
     longDirectionCheck(longDir2, long2);
  
     dLat = (lat1 - lat2) ;
     dLong = (long1 - long2);
  
     positivify(dLat);
     positivify(dLong);
     positivify(lat1);
     positivify(lat2);
  
      //convert all numbers to Rad
      dLat = convertRadians(dLat);
      dLong = convertRadians(dLong);
      lat1 = convertRadians(lat1);
      lat2 = convertRadians(lat2);
  
      double R = 3959.9;
      double num1 = sin(dLat/2);
      double num2 = sin(dLong/2);
  
  
  
      double a = pow(num1,2) + cos(lat1) * cos(lat2) *
                 pow(num2,2);
      double c = 2 * atan2(sqrt(a), sqrt(1-a));
      double d = R * c;
      return d;
     }
  
   double latDirectionCheck(char check, double convert) {
       if(check == 'S') 
        convert = -convert;
        return convert;
   }
  
   double longDirectionCheck(char check, double convert) {
      if(check == 'E')
         convert = -convert;
         return convert;
      }
  
   double positivify(double num) {
      if (num &lt; 0) 
      num = num*(-1);
      return num;
   }
  
   bool compareFarDistance(double num1, double num2) {
      bool statement = false;
      if(num1 &gt; num2)
          statement = true;
          return statement; 
   }
  
   bool compareCloseDistance(double num1, double num2) {
      bool statement = false;
      if(num1 &lt; num2)
          statement = true;
          return statement;
   }
   double convertRadians(double num) {
     num = PI*(num/180);
     return num;
   }
  
   double convertDegrees(double num) {
      num = 180 * (num/PI);
      return num;
  
   }
  </code></pre>
  
  <p>Input: <code>23.4356/S 46.4731/W</code></p>
  
  <p>Distance Output: <code>4335.48</code></p>