Question

Program Description Write a program that calculates the distance between two places on Earth, based on...

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 Earth’s 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:

  1. Program must have header comments stating the author of the Program, date, and Program Description.
  2. Include the math.h header file
  3. Initialize a variable with the value of earth’s radius. (Take earth’s radius as i).
  4. 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
  5. Step 4 has to be repeated for accepting the values of Starting Longitude, Ending Latitude, and Ending Longitude.
  6. 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 = Earth’s Radius

Haversine Formula:

R = earth’s 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

  1. 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<stdio.h>
#include<math.h>
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 =(Redues*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("\n");
   return 0;
}

----------------------------------------------------------------------

what else do i have to add??

0 0
Add a comment Improve this question Transcribed image text
Answer #1

If you have any doubts, please give me comment...

#include <stdio.h>

#include <math.h>

int main()

{

char choice;

const float Redues = 6371.01;

float start_lat, start_long, end_lat, end_long, Distance;

do{

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);

start_lat *= 0.0174533;

start_long *= 0.0174533;

end_lat *= 0.0174533;

end_long *= 0.0174533;

Distance = (Redues * 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 km\n", sqrt(Distance));

printf("\nDo you want continue(y/n): ");

scanf("\n%c", &choice);

}while(choice=='y' || choice=='Y');

return 0;

}

Add a comment
Know the answer?
Add Answer to:
Program Description Write a program that calculates the distance between two places on Earth, based on...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In C programming, code the following function: Write the function Location() that takes in two pairs...

    In C programming, code the following function: Write the function Location() that takes in two pairs of DEGREE (latitude, longitude) coordinates and returns the great-circle-distance between the points on the surface of the Earth, which is calculated using the formula: d = R acos[ cos(latA)cos(latB)cos(lonB-lonA) + sin(latA)sin(latB) ] where (latA,lonA) and (latB,lonB) are the RADIAN coordinates for the two points, R = 6368 km is the radius of the Earth (provided in the template as a global variable), d is...

  • The following C++  code contains an incomplete program that should be able to calculate the distance between...

    The following C++  code contains an incomplete program that should be able to calculate the distance between a series of geocoded locations. Two parts of the program need to be completed: 1. The portion of the main() function that calculates the distances between each of the hard-coded 5 locations, and stores it in a two-dimensional array declared as distances. 2. A portion of the calculateDistanceBetweenLocations(l1, l2) function; omitted code spaces are designed with a // TODO: comment. The code is properly...

  • (The cities.txt file is just a list of almost 30,000 cities and their distance from Charlotte)...

    (The cities.txt file is just a list of almost 30,000 cities and their distance from Charlotte) Your goal is to print the cities in United States sorted in the increasing order of distance from Charlotte. Download from Canvas the text file (cities.txt containing the latitude and longitude information of nearly 30,000 cities in the United States. Calculate the distance from Charlotte to each of these cities. Sort the cities in ascending order of distance, and print the sorted list along...

  • Write a C program that calculates the percent saves for a soccer goalie for 4 games...

    Write a C program that calculates the percent saves for a soccer goalie for 4 games and the overall percentage of saves which is saves divided by the sum of goals plus saves * In this program I used 4 variables of type int, and 1 of type float, and 1 of type char (for the buffer clearing statement required). * This program requires an introductory statement to the user. * This program requires a loop structure (a for loop...

  • I'm trying to write a program in C that calculates the area of a rectangle. I...

    I'm trying to write a program in C that calculates the area of a rectangle. I need to have a function that gets dimensions from a user and stores them with pointers and addresses and another function that calculates the area... my question is how do i access that values from the dimension function so that I can use it in my calculation and main function.. for example. void userDimensions(float *base, float *height){ scanf("%lf" , base); scanf("%lf", height); } float...

  • a.) Write a C++ program that calculates the value of the series sin x and cos...

    a.) Write a C++ program that calculates the value of the series sin x and cos x, sin 2x or cos 2x where the user enters the value of x (in degrees) and n the number of terms in the series. For example, if n= 5, the program should calculate the sum of 5 terms in the series for a given values of x. The program should use switch statements to determine the choice sin x AND cos x, sin...

  • So I have a question in regards to my program. I'm learning to program in C...

    So I have a question in regards to my program. I'm learning to program in C and I was curious about the use of functions. We don't get into them in this class but I wanted to see how they work. Here is my program and I would like to create a function for each of my menu options. I created a function to display and read the menu and the option that is entered, but I would like to...

  • Write a C program that calculates exact change. In order to receive full credit, please remember...

    Write a C program that calculates exact change. In order to receive full credit, please remember that only int arithmetic is exact, so you’ll need to break up your double into two ints, the one before the decimal point and the one after the decimal point. Another point worth mentioning is that the % operator gives the remainder. In other words, when working with int values, 9 / 5 = 1 whereas 9 % 5 = 4. Keep this in...

  • Write a complete C program. Define a structure type element_t to represent one element from the...

    Write a complete C program. Define a structure type element_t to represent one element from the periodictable of elements. Components should include the atomic number (aninteger); the name, chemical symbol, and class (strings); a numeric field forthe atomic weight; and a seven-element array of integers for the number ofelectrons in each shell. The following are the components of an element_t structure for sodium.11 Sodium Na alkali_metal 22.9898 2 8 1 0 0 0 0 Have the user enter the data...

  • I need this in c++ please Write a Map class that is composed of a Location...

    I need this in c++ please Write a Map class that is composed of a Location class. Location class has three private variable string nameOfCity, double variables, latitude and longitude. It has a constructor to initialize these and also the usual getters. It has three functions: string toString() which prints :double getFlyingTime(Location l) which returns the flying time between this and location l. It uses the formula that time = distance/speed. speed = 673 miles/hour. No need to convert to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT