# Anyone see what is wrong with this code?

• 02-13-2002
Wise1
Anyone see what is wrong with this code?
What's up, :)

I'm writing a program in C to calculate the distance between two latitude/longitude coordinates. the below code is that I wrote. It is not working for some reason and I'm clueless to what is wrong. Maby you can catch something that I'm missing. You have any ideas? Any help would be great. Thanks in advance! :)

Peace
Wise1

Code:

```#include<stdio.h> #include<math.h> #include<conio.h> main(){   //Declarations   double pi=3.14159265358979,a,c,d,dlat,dlon,lat1,lat2,lon1,lon2;   int days,hours,s,r=3956;   //Header   printf("Origin Coordinates \n  1) 16, 64 \t\t Speed: 20 mph \n  2) 32, 64 (Bermuda) \t Speed: 10 mph \n\nDestination Coordinates \n  1) 26, 80 (Ft. Lauderdale) \n\n\n");   //Read Input   printf("Please Enter the Origin Coordinates: ");   scanf("%f, %f",&lat1,&lon1);   printf("Please Enter the Destination Coordinates: ");   scanf("%f, %f",&lat2,&lon2);   printf("Please Enter the Speed of Travel: ");   scanf("%d",&s);   //Convert Coordinates From Decimal Degrees to Radians   lat1*=pi/180;   lat2*=pi/180;   lon1*=pi/180;   lon2*=pi/180;   //The Haversine Formula   dlat=lat2-lat1;   dlon=lon2-lon1;   a=((sin(dlat/2))*(sin(dlat/2)))+cos(lat1)*cos(lat2)*((sin(dlon/2))*(sin(dlon/2)));   c=2*atan2(sqrt(a),sqrt(1-a));   d=r*c;   //Find Time   hours=d/s;   days=hours/24;   hours-=days*24;   //Print Output   printf("\n\nDistance: %f Statute Miles \nSpeed: %d mph\nTime (Days/Hours): %d/%d",d,s,days,hours);   getch(); }```
• 02-13-2002
Salem
> double pi=3. 14159265358979
1. it has a space
2. use M_PI in math.h (which you already include)

> scanf("%f, %f",&lat1,&lon1);
You're using the wrong conversion for reading into doubles

scanf("%lf, %lf",&lat1,&lon1);

> It is not working for some reason and I'm clueless to what is wrong
Assuming that the input was correct was the first mistake
The second was not trying the obvious step of printing them straight back to the user for verification
• 02-13-2002
Wise1
What's up Salem, :)

Yep that was it. Thanks! :)

Peace
Wise1