need more help please

This is a discussion on need more help please within the C Programming forums, part of the General Programming Boards category; Code: #include <stdio.h> main() { int day_code; /* day_code = 0 means the month starts on Sun day_code = 1 ...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    40

    need more help please

    Code:
    #include <stdio.h>
    
    main()
    {
      int day_code; /* day_code = 0 means the month starts on Sun
                          day_code = 1 means the month starts on Mon
                          day_code = 2 means the month starts on
                          Tues, etc.  */
      int days_in_month;     /* number of days in month currently
                              being printed */
      int leap_year = 0; /* 1 means leap year; 0 means no leap year */
      int day;       /* counter for day of month */
      int month;     /* month = 1 is Jan, month = 2 is Feb, etc. */
    
      int year;
      int f;
      int d;
      int c;
    
      do {
        printf( "Enter year: " );
        scanf( "%d", &year );
      } while ( year < 1776 );
    
      if ((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0)))
        {
            leap_year = 1;
        }
      printf( "%d", leap_year );
      c = year / 100;
      d =( year % 100 ) - 1 ;
      f = 1 + (( 13 * 11 - 1 ) / 5) + d + ( d / 4 ) + ( c / 4 ) -( 2*c ) ;
      day_code = f % 7;
      if (leap_year == 1 )
        {
          day_code=day_code-1;
        }
    
      for ( month = 1; month <= 12; month++ ) {
        switch ( month ) { /* print name and set days_in_month */
        case 1:
          printf( "\n\nJanuary" );
          days_in_month = 31;
          break;
        case 2:
          printf( "\n\nFebruary" );
          if( leap_year == 1 )
            {
                 days_in_month = 29;
            }
          else if( leap_year ==0 )
            {
                 days_in_month = 28;
            }
          break;
        case 3:
          printf( "\n\nMarch" );
          days_in_month = 31;
          break;
        case 4:
          printf( "\n\nApril" );
          days_in_month = 30;
          break;
        case 5:
          printf( "\n\nMay" );
          days_in_month = 31;
          break;
        case 6:
          printf( "\n\nJune" );
          days_in_month = 30;
          break;
        case 7:
          printf( "\n\nJuly" );
          days_in_month = 31;
          break;
        case 8:
          printf( "\n\nAugust" );
          days_in_month = 31;
          break;
        case 9:
          printf( "\n\nSeptember" );
          days_in_month = 30;
          break;
        case 10:
          printf( "\n\nOctober" );
          days_in_month = 31;
          break;
        case 11:
          printf( "\n\nNovember" );
          days_in_month = 30;
          break;
        case 12:
          printf( "\n\nDecember" );
          days_in_month = 31;
          break;
        }
    
        printf( "\n\nSun  Mon  Tue  Wed  Thu  Fri  Sat\n" );
    
        /* advance printer to correct position for first date */
        for ( day = 1; day <= 1 + day_code * 5; day++ )
        {
          printf( " " );
        }
    
        /* print the dates for one month */
    
          for ( day = 1; day <= days_in_month; day++ ) {
          printf( "%2d", day );
          if ( ( day + day_code ) % 7 > 0 ) /* before Sat? */
            /* move to next day in same week */
           {
               printf( "   " );
           }
          else  /* skip to next line to start with Sun */
            {
               printf( "\n " );
            }
    
           }
    
        /* set day_code for next month to begin */
        day_code = ( day_code + days_in_month ) % 7;
      }
    }
    and the problem is this:

    output for january:

    Code:
    Enter year: 2008
    1
    
    January
    
    Sun  Mon  Tue  Wed  Thu  Fri  Sat
           1    2    3    4    5    6
      7    8    9   10   11   12   13
     14   15   16   17   18   19   20
     21   22   23   24   25   26   27
     28   29   30   31

    its one day off please help

  2. #2
    moi
    moi is offline
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946

    Re: need more help please

    Originally posted by blindleaf
    [CODE]
    its one day off please help
    so, insert a "-1" or "+1" wherever it is relevant in the code. you wrote it, you should know where that is.
    hello, internet!

  3. #3
    Registered User datainjector's Avatar
    Join Date
    Mar 2002
    Posts
    356
    i would have helped ya but your code is just to neat ...
    "I wish i could wish my wishs away"

    "By indirections find directions out" -- William Shakespears

    "Do what thou wilt shall be the whole of the law" -- Crowley "THE BEAST 666"

    Mizra -> love = Death...
    RDB(Rocks yooo)..

    http://www.cbeginnersunited.com

    Are you ready for the Trix ???

  4. #4
    Registered User
    Join Date
    Oct 2002
    Posts
    40
    Originally posted by datainjector
    i would have helped ya but your code is just to neat ...
    huh? yea thats how it should be its for school, if i dont do it neat i get points off, hehe, any help would be appreciated thanks

  5. #5
    TransparentMember correlcj's Avatar
    Join Date
    Jun 2002
    Posts
    378
    A short cut would be to highlight all and press ALT F8.
    "Be formless, shapeless, like water... You put water into a cup, it becomes the cup, you put water into a bottle, it becomes the bottle, you put it in a teapot, it becomes the teapot... Now water can flow, or it can crash, be water my friend."
    -Bruce Lee

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