1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
// Distance Structures Project.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <string.h>
#include "math.h"
#define MAX 4
#define PI 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248
double deg2rad(double deg);
double getDistance(double LA1, double LO1, double LA2, double LO2, double ret);
struct Airport {
double Lat, Long, Answer, Elevation, Mvar;
char Code[MAX];
double getDistance(double LA1, double LO1, double LA2, double LO2, double ret) {
ret = acos(sin((deg2rad(LA1))) * sin(deg2rad(LA2)) + cos(deg2rad(LA1)) * cos(deg2rad(LA2)) * (cos(deg2rad(LO1) - deg2rad(LO2))));
ret = ret * 10800 / PI;
return ret;
}
}Port1, Port2;
int main()
{
double answer;
printf("Please enter code of airport 1 >");
scanf("%s", Port1.Code);
printf("Please enter latitude of airport %s >", Port1.Code);
scanf("%lf", &Port1.Lat); // It goes wrong after here.
printf("Please enter longitude of airport %s >", Port1.Code);
scanf("%lf", &Port1.Long);
printf("Please enter magnetic variation of airport %s >", Port1.Code);
scanf("%lf", &Port1.Mvar);
printf("Please enter elevation of airport %s >", Port1.Code);
scanf("%lf", &Port1.Elevation);
//Second airport
printf("Please enter code of airport 2 >");
scanf("%s", Port2.Code);
printf("Please enter latitude of airport %s >", Port2.Code);
scanf("%lf", &Port2.Lat);
printf("Please enter longitude of airport %s >", Port2.Code);
scanf("%lf", &Port2.Long);
printf("Please enter magnetic variation of airport %s >", Port2.Code);
scanf("%lf", &Port2.Mvar);
printf("Please enter elevation of airport %s >", Port2.Code);
scanf("%lf", &Port2.Elevation);
answer = (double Port1.getDistance(answer));
return 0;
}
double deg2rad(double deg) {
return (deg * PI / 180);
}
|