I once again found a little time to toy with C Programming. I have applied the helpful advice from this message board since my last post. I used the utility on http://www.fcc.gov/mb/audio/bickel/DDDMMSS-decimal.html
to check my output. I was pleased that my program output matched that of the utility except on my final test input of 1 degree 1 minute 1 second. Please see the comments at the end of my program for details.
/* Name: TODECDEG.C */
/* Purpose: Convert Degrees Minutes Seconds to Decimal Degrees */
/* Author: MarkTheSpark */
/* Date: November 19, 2007 */
/* Compiler: Pacific C for MS-DOS, v7.51 */#include
double deg_min_sec = 0, decimal_deg = 0;
double mind = 0, secd = 0;
int deg = 0, min = 0, sec = 0;
printf("Enter Degrees Minutes Seconds: ");
deg = deg_min_sec; /* conversion during assignment */
min = (deg_min_sec - deg) * 100;
sec = ((deg_min_sec - deg) * 100 - min) * 100;
mind = (double) min / 60; /* http://c-faq.com/expr/truncation1.html
secd = (double) sec / 3600;
decimal_deg = deg + mind + secd;
printf("Decimal Degrees: %f
/* Sample output:
Enter Degrees Minutes Seconds: 1.0101
Decimal Degrees: 1.016667
Press any key to continue ...
This conversion does not agree withhttp://www.fcc.gov/mb/audio/bickel/DDDMMSS-decimal.html
Their utility yields 1.016944. Why?
Any help would be greatly appreciated!