New to C...

This is a discussion on New to C... within the C++ Programming forums, part of the General Programming Boards category; I need help with my program, it's a Julian Date conversion. The part that i'm having difficulty with is when ...

  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    15

    Unhappy New to C...

    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.

  2. #2
    Codigious FingerPrint's Avatar
    Join Date
    Mar 2006
    Posts
    60
    You should go to the C section and post there.
    Code:
    /* ------------------------------------------------------------------*/
                               // INSERT CODE HERE
    /* ------------------------------------------------------------------*/

  3. #3
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    >> I dont know how to get only the numbers after the decimal

    Say the varible that you want to get the decimal numbers from is x:
    Code:
    float y = (float)x;
    y *= 6;
    int z = (int)y;
    There is your decimal numbers in z.

  4. #4
    Registered Luser risby's Avatar
    Join Date
    Jun 2006
    Posts
    72
    Quote Originally Posted by Queatrix
    >> I dont know how to get only the numbers after the decimal

    Say the varible that you want to get the decimal numbers from is x:
    Code:
    float y = (float)x;
    y *= 6;
    int z = (int)y;
    There is your decimal numbers in z.
    Hmmm, let's see now ...

    111111.111111 * 6 = 666666.666666

    Perhaps you'd better write a test harness for your algorithm Queatrix
    ===
    Don't grumble about what you can't have;
    be grateful you don't get what you deserve.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21