0

I am creating a program that for my Class that is calculating the distance between two latitude and longitude points. I have got it up and running on the console, but after I enter the first two data points the console closes. I am wondering if I am forgetting something at the end of my code. Thanks!

#include <stdio.h>  
#include <math.h> 

//Pi number in math 
#define M_PI 3.14159265358979323846
//This is the radius of the earth in KM 
#define R 3959




int main (void)
    {
    double lat1;
    double lon1; 
    double lat2; 
    double lon2;
    double phi1; 
    double phi2; 
    double theta1; 
    double theta2; 
    double phi1R;
    double phi2R;
    double theta1R; 
    double theta2R;
    double c;
    int d; 


        //The User's initial Input for Point 1
        printf("Please Enter Your Latitude Longitude foroik Point 1\n");
        scanf ("%d%d", &lat1, &lon1);
        printf("Please Enter Your Latitude and Longitude for Point 2\n");
        scanf("%d%d", &lat2, &lon2);



    //Way of Declaring which side of the World We are on 

    if (lat1>0) 
        {
            phi1= 90-lat1;
        }
    else 
        {
            phi1=90+lat1;
        }

    if (lat2>0)
        {
            phi2=90-lat2;
        }
    else 
        {
            phi2=90+lat2;
        }

    if (lon1>0) 
        {
            theta1=lon1;
        }
    else 
        {
            theta1=-lon1;
        }

    if (lon2>0) 
        {
            theta2=lon2;
        }
    else 
        {
            theta2=-lon2;
        }

    phi1R = (phi1*M_PI)/180; 
    phi2R = (phi2*M_PI)/180; 
    theta1R = (theta1*M_PI)/180; 
    theta2R = (theta2*M_PI)/180; 


    //This is our Haversine formula to calculate the two distances between two points
    c = sin(phi1R)*sin(phi2R)*cos(theta1R-theta2R)+cos(phi1R)*cos(phi2R);


    //The shortest great circle distance between two points

    d = R*acos(c);

        printf("The distance between the two points is %d \n", d);





    return (0);
}
  • 1
    possible duplicate of [Preventing console window from closing on Visual Studio C/C++ Console application](http://stackoverflow.com/questions/1775865/preventing-console-window-from-closing-on-visual-studio-c-c-console-applicatio) – Paul Hankin Sep 23 '14 at 01:52
  • 1
    `sscanf` with `%d` format specifier expects arguments to be of type `int` (you are passing `double`). You probably want to use `%f`. – SleuthEye Sep 23 '14 at 01:54

0 Answers0