|
-
November 11th, 2016, 07:23 PM
#1
How to calculate Nautical miles between two airport coordinates with a structure?
Hello. I am trying to make a program where I need to calculate the distance between two airports using a structure. The program needs to ask the user to enter a code such as "SAN" for the San Diego airport, then ask for its coordinates, elevation, and magnetic variation. Then it will need to ask the same for the the same for a different airport. I need to have a function inside of the struct called getDistance that uses a formula we made earlier to calculate the Nautical miles. There needs to be another formula inside of the structure called getDistance2 that only takes one airport as a parameter and breaks down the elements of the airports and call the getDistance to calculate the nautical miles. I made a structure where I put in a formula that I made earlier. I tested it with the printf to see if it will output the right number, but it gives me a completely different number. I am also trying to use a string for the code of the airport, but can't seem to get it to work with scanf. I am required to use the stdafx.h. I would really appreciate it if you can show me how to fix the structure and fix it so I can make the program ask the user for the code of the airport. Also, how would I ask for the second airport? Thank you.
Code:
// 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);
typedef struct {
double Lat1, Long1, Lat2, Long2, 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;
}
}Airport;
int main()
{
struct Airport;
printf("Please enter code of airport 1 >");
scanf("%s", Code);
printf("Please enter latitude of airport %s >", Code);
scanf("%d", Code);
printf("Please enter longitude of airport %s >", Code);
scanf("%d", Code[]);
printf("Please enter magnetic variation of airport %s >", Code);
scanf("%d", Code[]);
printf("Please enter elevation of airport %s >", Code);
scanf("%d", Code[]);
return 0;
}
double deg2rad(double deg) {
return (deg * PI / 180);
}
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|