Question
Program Description Write a program that calculates the distance between two places on Earth, based on their latitude and longitude. Prompt the user to enter
Program Description
Write a program that calculates the distance between two places on Earth, based on their latitude and longitude. Prompt the user to enter the latitude and longitude of two places. The Earths mean radius is to be taken as 6371.01 km. Use user-defined variables with descriptive names wherever necessary. Following steps will have to be followed:
- Program must have header comments stating the author of the Program, date, and Program Description.
- Include the math.h header file
- Initialize a variable with the value of earths radius. (Take earths radius as i).
- Prompt the user to enter the Starting Latitude. Read that number into a user-defined variable. (Remember to convert the input to float. Also the input needs to be further converted to radians.) You may use value of PI as 3.141592654
- Step 4 has to be repeated for accepting the values of Starting Longitude, Ending Latitude, and Ending Longitude.
- Compute the distance between the two places using any one of the following formulas:
Spherical Law of Cosines:
distance =
R*acos(sin(start_lat)*sin(end_lat)+cos(start_lat)*cos(end_lat)*cos(start_long- end_long))
where R = Earths Radius
Haversine Formula:
R = earths radius difflat = end_lat start_lat difflong = end_long start_long a = sin(difflat/2) + cos(start_lat) * cos(end_lat) * sin(diflong/2) c = 2 * atan2(sqrt(a), sqrt(1-a)) d = R * c
- Display the distance between the two places as:
The distance between the two places is (calculated distance) kms.
----------------------------------------------------------------------------------------------------------------------------------
in the above is a question about C program that calculates the distance between two places on Earth, i did this cod can any one check it for me and help me with Conversion of degrees to radians and also how i can add an Extra loop Construct for Making the program execute continuously, till user asks to exit! OR Maybe the way constants are declared in the preprocessor phase of the program execution!
this is my coding
#include #include #include #include #include name date and discrption of the program
int main() { const float Redues=6371.01; float start_lat, start_long, end_lat, end_long, Distance; printf("Input Start Latitude: "); scanf("%f", &start_lat); printf("Input Start Longitude: "); scanf("%f", &start_long); printf("Input End Latitude: "); scanf("%f", &end_lat); printf("Input End Longitude: "); scanf("%f", &end_long); Distance =(R*acos(sin(start_lat)*sin(end_lat)+cos(start_lat)*cos(end_lat)*cos(start_long- end_long))); printf("Distance between the said points: %.2f", sqrt(Distance)); printf(" km"); printf(" "); return 0; }
----------------------------------------------------------------------
what else do i have to add??
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started