Convert DegMinSec to Decimal Degrees
Hello,
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.0101.
Please see the comments at the end of my program for details.
Any help would be greatly appreciated!Code:/* Name: TODECDEG.C */ /* Purpose: Convert Degrees Minutes Seconds to Decimal Degrees */ /* Author: JacquesLeJock */ /* Date: November 19, 2007 */ /* Compiler: Pacific C for MS-DOS, v7.51 */ #include <stdio.h> main() { 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: "); scanf("%lf", °_min_sec); 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\n\n", decimal_deg); return 0; } /* Sample output: Enter Degrees Minutes Seconds: 1.0101 Decimal Degrees: 1.016667 Press any key to continue ... */ /* Note: This conversion does not agree with http://www.fcc.gov/mb/audio/bickel/DDDMMSS-decimal.html. Their utility yields 1.016944. Why? */
Regards,
Jacques



LinkBack URL
About LinkBacks


