I need help with my program, it's a Julian Date conversion. The part that i'm having difficulty with is when you enter a julian date, there are 6 numbers after the decimal. How do i get the 6 numbers after the decimal so that i can calculate the hours, minutes and seconds?? here's my code:
Code:
#include <stdio.h>
int main()
{
double jdn;
long lc, nc, ic, jc;
int day, month, year, hours, minutes, seconds, a, b, meridian ;
/*print title*/
printf(" * * Julian Date Conversion * *\n") ;
/*ask user for a Julian date */
printf ("Please enter a Julian Date:\n") ;
scanf("%lf", &jdn) ;
if (jdn <= 2299160)
printf ("Error: You have entered an invalid number.") ;
/* Perform calculations */
lc = jdn + 68569;
nc = 4 * lc / 146097;
lc = lc - (146097 * nc + 3) / 4;
ic = 4000 * (lc + 1) / 1461001;
lc = lc - 1461 * ic / 4 + 31;
jc = 80 * lc / 2447;
day = lc - 2447 * jc / 80;
lc = jc / 11;
month = jc + 2 - 12 * lc;
year = 100 * (nc - 49) + ic + lc;
hours= jdn % * 24 ;
a= hours % 60 ;
minutes= a * 60 ;
b= minutes % 60 ;
seconds= b * 60 ;
if (meridian >= 12)
printf ("p.m.") ;
else printf ("a.m.") ;
/* print date*/
printf("%d %d %d %d %d %d\n", month, day, year, hours, minutes, seconds,
meridian);
return 0;
}
my problem more specifically, is in the calculations portion where hours begins. to help understand what i mean:
Calculation of time portion:
(0.1 days equals 0.1 * 24 hours = 2 hours (remainder 0.4 hours),
0.4 * 60 minutes = 24 minutes (remainder 0.0 seconds)
0.0 * 60 seconds = 0 seconds
I dont know how to get only the numbers after the decimal, or if there is another way i dont see it yet, so that i can calculate the hours, minutes, and seconds!! please help.