double - C program not printing values -
i writing program converts decimal degrees degrees, minutes, seconds. supposed do:
-118.1406209154 = 118 degrees 8 minutes 26.2342 seconds west. w if negative either west longitude or south latitude 118 degrees left of decimal place 8 multiply decimal portion (0.140620915) 60 decimal minutes (8.4372549). minutes left of decimal place. 26.2353 multiply decimal portion (0.4372549) 60 decimal seconds.
this code have far, however, problem when run prints decimaldegrees value , nothing else. cannot figure out why. tip/help appreciated.
double decimaldegrees = -118.1406209154; double degrees; double minutes; double seconds; char longitude; char latitude; double temp; int main(int argc, char **argv) { minutes = decimaldegrees - (int)decimaldegrees; //get decimal portion of decimaldegrees degrees = decimaldegrees - minutes; //get degrees removing decimal portion minutes = minutes*60.0; temp = minutes - (int)minutes; //get decimal portion minutes = minutes - temp; //remove decimal portion minutes seconds = temp * 60.0; printf("%0.10lf ", decimaldegrees); printf("%lf degrees ", degrees); printf("%lf minutes ", minutes); printf("%0.4lf seconds ", seconds); return 0; }
this works me fine, far. perhaps should attempt different compiler, if using unix based system, try using gcc if haven't already, or xcode if using mac, , if running windows mingw has been popular choice (a gcc solution windows).
taking account others have said, better code little while @ it. paul suggested, use of %lf
unnecessary use in printf here, if intend user enter own values in later on, use %lf
reading in doubles using scanf()
.
Comments
Post a Comment