#include #include "geography.h" /** * Computes the distance of a path given the latitudes and longitudes * of the points on the path. The coordinates are read from standard input * and assumed to be in degrees. The output is the number of points in the * path and the total distance using the great circle distance between adjacent * points. * * Compile and link with * gcc -Wall -std=c99 -pedantic distance.c * gcc -Wall -std=c99 -pedantic more_math.c * gcc -Wall -std=c99 -pedantic geography.c * gcc -o Distance distance.o more_math.o geography.o -lm * * @version 0.2 2018-09-06 colatitude now works in radians * @version 0.1 2017-09-01 */ int main() { double total_distance = 0.0; location prev; location curr; // upgraded to read user input (no more hard-coding) and calculate // the distance along a multi-point route (using a loop!) int n = 0; while (scanf("%lf %lf", &curr.lat, &curr.lon) == 2) { if (curr.lat < -90.0 || curr.lat > 90.0) { fprintf(stderr, "Invalid latitude\n"); return 1; } n++; if (n >= 2) { total_distance += distance(&prev, &curr); } prev = curr; } printf("%d points; total distance %lf miles\n", n, total_distance); }