?
Solved

Calendar Program question for gj62

Posted on 2003-03-10
10
Medium Priority
?
269 Views
Last Modified: 2013-12-03
gj62...I got the program done, needs a little more work on it but it works..
I got minor bug though.... Can you please look at my February area and tell me how to fix it... What happens is that when the leap year is keeyed in the program recognizes that its leap year and it adds one day to february but when it comes to calculation it goes with 28...So if February 29th is on friday march first should be on saturday but it uses friday.....


Another question. Once the calendar is displayed, there should be a prompt for another year so if the answer is Y should continue and print another calendar if no should terminate, I'm kinda stuck on that one, please help.....

Here is the code that I got so far....

Thanks a lot                  CALENDAR.C
**************************************************************************************
#include <stdio.h>



int main (void)
{

      int year;
      int firstDayOfYear;
      int firstDayOfFeb;
      int firstDayOfMarch;
      int firstDayOfApril;
      int firstDayOfMay;
      int firstDayOfJune;
      int firstDayOfJuly;
      int firstDayOfAugust;
      int firstDayOfSeptember;
      int firstDayOfOctober;
      int firstDayOfNovember;
      int firstDayOfDecember;

      int lineCount;
      int day;
      int x;

      int January = 31;
      int February = 28;
      int March = 31;
      int April = 30;
      int May = 31;
      int June = 30;
      int July = 31;
      int August = 31;
      int September = 30;
      int October = 31;
      int November = 30;
      int December = 31;

      //char answer;

      printf("Please enter the year:\n");
      scanf ("%d", &year);





      firstDayOfYear = (((year - 1) * 365) + ((year - 1) / 4) - (year - 1 / 100) +  (year - 1 / 400)) % 7;

      firstDayOfFeb = (January + firstDayOfYear) % 7;
      firstDayOfMarch = (February + firstDayOfFeb) % 7;
      firstDayOfApril = (March + firstDayOfMarch) % 7;
      firstDayOfMay = (April + firstDayOfApril) % 7;
      firstDayOfJune = (May + firstDayOfMay) % 7;
      firstDayOfJuly = (June + firstDayOfJune) % 7;
      firstDayOfAugust = (July + firstDayOfJuly) % 7;
      firstDayOfSeptember = (August + firstDayOfAugust) % 7;
      firstDayOfOctober = (September + firstDayOfSeptember) % 7;
      firstDayOfNovember = (October + firstDayOfOctober) % 7;
      firstDayOfDecember = (November + firstDayOfNovember) % 7;


      {
                  

      printf("JANUARY\t%d\n\n", year);
      printf("Sun\tMon\tTue\tWed\tThu\tFri\tSat\n");

      lineCount = 0;
      January = 31;

      for (x = 0; x < firstDayOfYear; x++)
      {
            printf("\t");
            lineCount++;
      }

      for (day = 1; day <= January; day++)

      {
            if (lineCount > 6)
            {
                  printf("\n\n");
                  lineCount = 0;
            }
            printf(" %d\t", day);
            lineCount++;
      }

      printf("\n\n\n");
      printf("FEBRUARY\t%d\n\n", year);
      printf("Sun\tMon\tTue\tWed\tThu\tFri\tSat\n");


      lineCount = 0;
      February = 28;

      if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0))
      {
            February++;

      }


      for (x = 0; x < firstDayOfFeb; x++)
      {      
            printf("\t");
            lineCount++;
      }

      for (day = 1; day <= February; day++)

      {
            if (lineCount > 6)
            {
                  printf("\n\n");
                  lineCount = 0;
            }
            printf(" %d\t", day);
            lineCount++;
      }
      

      printf("\n\n\n");
      printf("MARCH\t%d\n\n", year);
      printf("Sun\tMon\tTue\tWed\tThu\tFri\tSat\n");

      lineCount = 0;
      March = 31;

      for (x = 0; x < firstDayOfMarch; x++)
      {
            printf("\t");
            lineCount++;
      }

      for (day = 1; day <= March; day++)

      {
            if (lineCount > 6)
            {
                  printf("\n\n");
                  lineCount = 0;
            }
            printf(" %d\t", day);
            lineCount++;
      }


      printf("\n\n\n");
      printf("APRIL\t%d\n\n", year);
      printf("Sun\tMon\tTue\tWed\tThu\tFri\tSat\n");

      lineCount = 0;
      April = 30;

      for (x = 0; x < firstDayOfApril; x++)
      {
            printf("\t");
            lineCount++;
      }

      for (day = 1; day <= April; day++)

      {
            if (lineCount > 6)
            {
                  printf("\n\n");
                  lineCount = 0;
            }
            printf(" %d\t", day);
            lineCount++;
      }


      printf("\n\n\n");
      printf("MAY\t%d\n\n", year);
      printf("Sun\tMon\tTue\tWed\tThu\tFri\tSat\n");

      lineCount = 0;
      May = 31;

      for (x = 0; x < firstDayOfMay; x++)
      {
            printf("\t");
            lineCount++;
      }

      for (day = 1; day <= May; day++)

      {
            if (lineCount > 6)
            {
                  printf("\n\n");
                  lineCount = 0;
            }
            printf(" %d\t", day);
            lineCount++;
      }

        printf("\n\n\n");
      printf("JUNE\t%d\n\n", year);
      printf("Sun\tMon\tTue\tWed\tThu\tFri\tSat\n");

      lineCount = 0;
      June = 30;

      for (x = 0; x < firstDayOfJune; x++)
      {
            printf("\t");
            lineCount++;
      }

      for (day = 1; day <= June; day++)

      {
            if (lineCount > 6)
            {
                  printf("\n\n");
                  lineCount = 0;
            }
            printf(" %d\t", day);
            lineCount++;
      }


        printf("\n\n\n");
      printf("JULY\t%d\n\n", year);
      printf("Sun\tMon\tTue\tWed\tThu\tFri\tSat\n");

      lineCount = 0;
      July = 31;

      for (x = 0; x < firstDayOfJuly; x++)
      {
            printf("\t");
            lineCount++;
      }

      for (day = 1; day <= July; day++)

      {
            if (lineCount > 6)
            {
                  printf("\n\n");
                  lineCount = 0;
            }
            printf(" %d\t", day);
            lineCount++;
      }

      printf("\n\n\n");
      printf("AUGUST\t%d\n\n", year);
      printf("Sun\tMon\tTue\tWed\tThu\tFri\tSat\n");

      lineCount = 0;
      August = 31;

      for (x = 0; x < firstDayOfAugust; x++)
      {
            printf("\t");
            lineCount++;
      }

      for (day = 1; day <= August; day++)

      {
            if (lineCount > 6)
            {
                  printf("\n\n");
                  lineCount = 0;
            }
            printf(" %d\t", day);
            lineCount++;
      }

      printf("\n\n\n");
      printf("SEPTEMBER\t%d\n\n", year);
      printf("Sun\tMon\tTue\tWed\tThu\tFri\tSat\n");

      lineCount = 0;
      September = 30;

      for (x = 0; x < firstDayOfSeptember; x++)
      {
            printf("\t");
            lineCount++;
      }

      for (day = 1; day <= September; day++)

      {
            if (lineCount > 6)
            {
                  printf("\n\n");
                  lineCount = 0;
            }
            printf(" %d\t", day);
            lineCount++;
      }

      printf("\n\n\n");
      printf("OCTOBER\t%d\n\n", year);
      printf("Sun\tMon\tTue\tWed\tThu\tFri\tSat\n");


      lineCount = 0;
      October = 31;

      for (x = 0; x < firstDayOfOctober; x++)
      {
            printf("\t");
            lineCount++;
      }

      for (day = 1; day <= October; day++)

      {
            if (lineCount > 6)
            {
                  printf("\n\n");
                  lineCount = 0;
            }
            printf(" %d\t", day);
            lineCount++;
      }

      printf("\n\n\n");
      printf("NOVEMBER\t%d\n\n", year);
      printf("Sun\tMon\tTue\tWed\tThu\tFri\tSat\n");

      lineCount = 0;
      November = 30;

      for (x = 0; x < firstDayOfNovember; x++)
      {
            printf("\t");
            lineCount++;
      }

      for (day = 1; day <= November; day++)

      {
            if (lineCount > 6)
            {
                  printf("\n\n");
                  lineCount = 0;
            }
            printf(" %d\t", day);
            lineCount++;
      }

      printf("\n\n\n");
      printf("DECEMBER\t%d\n\n", year);
      printf("Sun\tMon\tTue\tWed\tThu\tFri\tSat\n");

      lineCount = 0;
      December = 31;

      for (x = 0; x < firstDayOfDecember; x++)
      {       printf("\t");
            lineCount++;
      }

      for (day = 1; day <= December; day++)

      {
            if (lineCount > 6)
            {
                  printf("\n\n");
                  lineCount = 0;
            }
            printf(" %d\t", day);
            lineCount++;
      }
            

      }
      }




















0
Comment
Question by:dmuran
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
10 Comments
 
LVL 6

Accepted Solution

by:
gj62 earned 80 total points
ID: 8104144
Here it is:

2 changes - first, I put the entire section in a while loop and asked the user if they want another calendar.  They can enter Y or y, anything else ends.

second, where you check for leap year, I recalculated the first day of the month.

That said, this could better be written by using functions, rather than one big main(), but that's more than 20 points worth... <grin>

#include <stdio.h>



int main (void)
{

     int year;
     int firstDayOfYear;
     int firstDayOfFeb;
     int firstDayOfMarch;
     int firstDayOfApril;
     int firstDayOfMay;
     int firstDayOfJune;
     int firstDayOfJuly;
     int firstDayOfAugust;
     int firstDayOfSeptember;
     int firstDayOfOctober;
     int firstDayOfNovember;
     int firstDayOfDecember;

     int lineCount;
     int day;
     int x;

     int January = 31;
     int February = 28;
     int March = 31;
     int April = 30;
     int May = 31;
     int June = 30;
     int July = 31;
     int August = 31;
     int September = 30;
     int October = 31;
     int November = 30;
     int December = 31;

     char keepGoing[10] = "Y";


     while( *keepGoing == 'Y' || *keepGoing == 'y')
       {
       printf("Please enter the year:\n");
     scanf ("%d", &year);





     firstDayOfYear = (((year - 1) * 365) + ((year - 1) / 4) - (year - 1 / 100) +  (year - 1 / 400)) % 7;

     firstDayOfFeb = (January + firstDayOfYear) % 7;
     firstDayOfMarch = (February + firstDayOfFeb) % 7;
     firstDayOfApril = (March + firstDayOfMarch) % 7;
     firstDayOfMay = (April + firstDayOfApril) % 7;
     firstDayOfJune = (May + firstDayOfMay) % 7;
     firstDayOfJuly = (June + firstDayOfJune) % 7;
     firstDayOfAugust = (July + firstDayOfJuly) % 7;
     firstDayOfSeptember = (August + firstDayOfAugust) % 7;
     firstDayOfOctober = (September + firstDayOfSeptember) % 7;
     firstDayOfNovember = (October + firstDayOfOctober) % 7;
     firstDayOfDecember = (November + firstDayOfNovember) % 7;


     {
               

     printf("JANUARY\t%d\n\n", year);
     printf("Sun\tMon\tTue\tWed\tThu\tFri\tSat\n");

     lineCount = 0;
     January = 31;

     for (x = 0; x < firstDayOfYear; x++)
     {
          printf("\t");
          lineCount++;
     }

     for (day = 1; day <= January; day++)

     {
          if (lineCount > 6)
          {
               printf("\n\n");
               lineCount = 0;
          }
          printf(" %d\t", day);
          lineCount++;
     }

     printf("\n\n\n");
     printf("FEBRUARY\t%d\n\n", year);
     printf("Sun\tMon\tTue\tWed\tThu\tFri\tSat\n");


     lineCount = 0;
     February = 28;

     if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0))
     {
          February++;

          firstDayOfMarch        = (++firstDayOfMarch)%7;
          firstDayOfApril        = (++firstDayOfApril)%7;
          firstDayOfMay          = (++firstDayOfMay)%7;
          firstDayOfJune         = (++firstDayOfJune)%7;
          firstDayOfJuly         = (++firstDayOfJuly)%7;
          firstDayOfAugust       = (++firstDayOfAugust)%7;  
          firstDayOfSeptember    = (++firstDayOfSeptember)%7;
          firstDayOfOctober      = (++firstDayOfOctober)%7;
          firstDayOfNovember     = (++firstDayOfNovember)%7;
          firstDayOfDecember     = (++firstDayOfDecember)%7;

     }


     for (x = 0; x < firstDayOfFeb; x++)
     {    
          printf("\t");
          lineCount++;
     }

     for (day = 1; day <= February; day++)

     {
          if (lineCount > 6)
          {
               printf("\n\n");
               lineCount = 0;
          }
          printf(" %d\t", day);
          lineCount++;
     }
     

     printf("\n\n\n");
     printf("MARCH\t%d\n\n", year);
     printf("Sun\tMon\tTue\tWed\tThu\tFri\tSat\n");

     lineCount = 0;
     March = 31;

     for (x = 0; x < firstDayOfMarch; x++)
     {
          printf("\t");
          lineCount++;
     }

     for (day = 1; day <= March; day++)

     {
          if (lineCount > 6)
          {
               printf("\n\n");
               lineCount = 0;
          }
          printf(" %d\t", day);
          lineCount++;
     }


     printf("\n\n\n");
     printf("APRIL\t%d\n\n", year);
     printf("Sun\tMon\tTue\tWed\tThu\tFri\tSat\n");

     lineCount = 0;
     April = 30;

     for (x = 0; x < firstDayOfApril; x++)
     {
          printf("\t");
          lineCount++;
     }

     for (day = 1; day <= April; day++)

     {
          if (lineCount > 6)
          {
               printf("\n\n");
               lineCount = 0;
          }
          printf(" %d\t", day);
          lineCount++;
     }


     printf("\n\n\n");
     printf("MAY\t%d\n\n", year);
     printf("Sun\tMon\tTue\tWed\tThu\tFri\tSat\n");

     lineCount = 0;
     May = 31;

     for (x = 0; x < firstDayOfMay; x++)
     {
          printf("\t");
          lineCount++;
     }

     for (day = 1; day <= May; day++)

     {
          if (lineCount > 6)
          {
               printf("\n\n");
               lineCount = 0;
          }
          printf(" %d\t", day);
          lineCount++;
     }

       printf("\n\n\n");
     printf("JUNE\t%d\n\n", year);
     printf("Sun\tMon\tTue\tWed\tThu\tFri\tSat\n");

     lineCount = 0;
     June = 30;

     for (x = 0; x < firstDayOfJune; x++)
     {
          printf("\t");
          lineCount++;
     }

     for (day = 1; day <= June; day++)

     {
          if (lineCount > 6)
          {
               printf("\n\n");
               lineCount = 0;
          }
          printf(" %d\t", day);
          lineCount++;
     }


       printf("\n\n\n");
     printf("JULY\t%d\n\n", year);
     printf("Sun\tMon\tTue\tWed\tThu\tFri\tSat\n");

     lineCount = 0;
     July = 31;

     for (x = 0; x < firstDayOfJuly; x++)
     {
          printf("\t");
          lineCount++;
     }

     for (day = 1; day <= July; day++)

     {
          if (lineCount > 6)
          {
               printf("\n\n");
               lineCount = 0;
          }
          printf(" %d\t", day);
          lineCount++;
     }

     printf("\n\n\n");
     printf("AUGUST\t%d\n\n", year);
     printf("Sun\tMon\tTue\tWed\tThu\tFri\tSat\n");

     lineCount = 0;
     August = 31;

     for (x = 0; x < firstDayOfAugust; x++)
     {
          printf("\t");
          lineCount++;
     }

     for (day = 1; day <= August; day++)

     {
          if (lineCount > 6)
          {
               printf("\n\n");
               lineCount = 0;
          }
          printf(" %d\t", day);
          lineCount++;
     }

     printf("\n\n\n");
     printf("SEPTEMBER\t%d\n\n", year);
     printf("Sun\tMon\tTue\tWed\tThu\tFri\tSat\n");

     lineCount = 0;
     September = 30;

     for (x = 0; x < firstDayOfSeptember; x++)
     {
          printf("\t");
          lineCount++;
     }

     for (day = 1; day <= September; day++)

     {
          if (lineCount > 6)
          {
               printf("\n\n");
               lineCount = 0;
          }
          printf(" %d\t", day);
          lineCount++;
     }

     printf("\n\n\n");
     printf("OCTOBER\t%d\n\n", year);
     printf("Sun\tMon\tTue\tWed\tThu\tFri\tSat\n");


     lineCount = 0;
     October = 31;

     for (x = 0; x < firstDayOfOctober; x++)
     {
          printf("\t");
          lineCount++;
     }

     for (day = 1; day <= October; day++)

     {
          if (lineCount > 6)
          {
               printf("\n\n");
               lineCount = 0;
          }
          printf(" %d\t", day);
          lineCount++;
     }

     printf("\n\n\n");
     printf("NOVEMBER\t%d\n\n", year);
     printf("Sun\tMon\tTue\tWed\tThu\tFri\tSat\n");

     lineCount = 0;
     November = 30;

     for (x = 0; x < firstDayOfNovember; x++)
     {
          printf("\t");
          lineCount++;
     }

     for (day = 1; day <= November; day++)

     {
          if (lineCount > 6)
          {
               printf("\n\n");
               lineCount = 0;
          }
          printf(" %d\t", day);
          lineCount++;
     }

     printf("\n\n\n");
     printf("DECEMBER\t%d\n\n", year);
     printf("Sun\tMon\tTue\tWed\tThu\tFri\tSat\n");

     lineCount = 0;
     December = 31;

     for (x = 0; x < firstDayOfDecember; x++)
     {       printf("\t");
          lineCount++;
     }

     for (day = 1; day <= December; day++)

     {
          if (lineCount > 6)
          {
               printf("\n\n");
               lineCount = 0;
          }
          printf(" %d\t", day);
          lineCount++;
     }
         

     }

       printf("\n\nDo you want to print another calendar?:");
     scanf ("%s", keepGoing);

       }
       return 0;
}
0
 

Author Comment

by:dmuran
ID: 8104253
gj62,
I know it was worth more then 20 points sorry...
I'm going to put all in function, I just spent few hours yesterday but you deff. helped me a lot....

I'm going to test it now...

Thanks a lot

DM
0
 

Author Comment

by:dmuran
ID: 8104275
gj62....
It works good, thanks a lot....I'll make sure to put more points next time....

Thanks...

DM
0
Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

 
LVL 6

Expert Comment

by:gj62
ID: 8104294
Glad I could help - post again if you run into problems...
0
 

Author Comment

by:dmuran
ID: 8106803
gj...
I was trying to get everything in the function but I get one error message I cant really figure out... here is the whole program...

Thanks a lot...
If you get a chance just let me know what am doing wrong, you dont have to spend too much time and debug it.....

DM

***********************************************************

#include <stdio.h>

void printCalendar (  int year, int firstDayOfYear, int firstDayOfFeb,
                                int firstDayOfMarch, int firstDayOfApril,  int firstDayOfMay,
                                int firstDayOfJune,  int firstDayOfJuly,  int firstDayOfAugust,
                                int firstDayOfSeptember,  int firstDayOfOctober,  int firstDayOfNovember,
                                int firstDayOfDecember, int lineCount,  int day, int x, int January,
                                int February,  int March,  int April,   int May,
                              int June,  int July,  int August,    int September,
                                int October3, int November,  int December);
int main (void)
{

   
      int year;
    int firstDayOfYear;
    int firstDayOfFeb;
    int firstDayOfMarch;
    int firstDayOfApril;
    int firstDayOfMay;
    int firstDayOfJune;
    int firstDayOfJuly;
    int firstDayOfAugust;
    int firstDayOfSeptember;
    int firstDayOfOctober;
    int firstDayOfNovember;
    int firstDayOfDecember;

    int lineCount;
    int day;
    int x;

    int January = 31;
    int February = 28;
    int March = 31;
    int April = 30;
    int May = 31;
    int June = 30;
    int July = 31;
    int August = 31;
    int September = 30;
    int October = 31;
    int November = 30;
    int December = 31;

    char keepGoing[10] = "Y";


    while( *keepGoing == 'Y' || *keepGoing == 'y')
      {
      printf("Please enter the year:\n");
        scanf ("%d", &year);





    firstDayOfYear = (((year - 1) * 365) + ((year - 1) / 4) - (year - 1 / 100) +  (year - 1 / 400)) % 7;

    firstDayOfFeb = (January + firstDayOfYear) % 7;
    firstDayOfMarch = (February + firstDayOfFeb) % 7;
    firstDayOfApril = (March + firstDayOfMarch) % 7;
    firstDayOfMay = (April + firstDayOfApril) % 7;
    firstDayOfJune = (May + firstDayOfMay) % 7;
    firstDayOfJuly = (June + firstDayOfJune) % 7;
    firstDayOfAugust = (July + firstDayOfJuly) % 7;
    firstDayOfSeptember = (August + firstDayOfAugust) % 7;
    firstDayOfOctober = (September + firstDayOfSeptember) % 7;
    firstDayOfNovember = (October + firstDayOfOctober) % 7;
    firstDayOfDecember = (November + firstDayOfNovember) % 7;


    printCalendar      ( year, firstDayOfYear, firstDayOfFeb,
                                firstDayOfMarch, firstDayOfApril, firstDayOfMay,
                                firstDayOfJune, firstDayOfJuly, firstDayOfAugust,
                                firstDayOfSeptember, firstDayOfOctober, firstDayOfNovember,
                                firstDayOfDecember, lineCount, day,  x, January = 31,
                                February = 28, March = 31, April = 30, May = 31,
                              June = 30, July = 31, August = 31, September = 30,
                                October = 31, November = 30, December = 31);




        printf("\n\nDo you want to print another calendar?:");
        scanf ("%s", keepGoing);



        return 0;
}


void printCalendar       (int year, int firstDayOfYear, int firstDayOfFeb,
                                int firstDayOfMarch, int firstDayOfApril, int firstDayOfMay,
                                int firstDayOfJune, int firstDayOfJuly, int firstDayOfAugust,
                                int firstDayOfSeptember, int firstDayOfOctober, int firstDayOfNovember,
                                int firstDayOfDecember, int lineCount,  int day, int x, int January,
                                int February , int March, int April, int May ,
                              int June , int July,  int August, int September,
                                int October, int November, int December)
 
{

      {
      printf("JANUARY\t%d\n\n", year);
    printf("Sun\tMon\tTue\tWed\tThu\tFri\tSat\n");

    lineCount = 0;
    January = 31;

    for (x = 0; x < firstDayOfYear; x++)
    {
         printf("\t");
         lineCount++;
    }

    for (day = 1; day <= January; day++)

    {
         if (lineCount > 6)
         {
              printf("\n\n");
              lineCount = 0;
         }
         printf(" %d\t", day);
         lineCount++;
    }

    printf("\n\n\n");
    printf("FEBRUARY\t%d\n\n", year);
    printf("Sun\tMon\tTue\tWed\tThu\tFri\tSat\n");


    lineCount = 0;
    February = 28;

    if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0))
    {
         February++;

         firstDayOfMarch        = (++firstDayOfMarch)%7;
         firstDayOfApril        = (++firstDayOfApril)%7;
         firstDayOfMay          = (++firstDayOfMay)%7;
         firstDayOfJune         = (++firstDayOfJune)%7;
         firstDayOfJuly         = (++firstDayOfJuly)%7;
         firstDayOfAugust       = (++firstDayOfAugust)%7;  
         firstDayOfSeptember    = (++firstDayOfSeptember)%7;
         firstDayOfOctober      = (++firstDayOfOctober)%7;
         firstDayOfNovember     = (++firstDayOfNovember)%7;
         firstDayOfDecember     = (++firstDayOfDecember)%7;

    }


    for (x = 0; x < firstDayOfFeb; x++)
    {    
         printf("\t");
         lineCount++;
    }

    for (day = 1; day <= February; day++)

    {
         if (lineCount > 6)
         {
              printf("\n\n");
              lineCount = 0;
         }
         printf(" %d\t", day);
         lineCount++;
    }
   

    printf("\n\n\n");
    printf("MARCH\t%d\n\n", year);
    printf("Sun\tMon\tTue\tWed\tThu\tFri\tSat\n");

    lineCount = 0;
    March = 31;

    for (x = 0; x < firstDayOfMarch; x++)
    {
         printf("\t");
         lineCount++;
    }

    for (day = 1; day <= March; day++)

    {
         if (lineCount > 6)
         {
              printf("\n\n");
              lineCount = 0;
         }
         printf(" %d\t", day);
         lineCount++;
    }


    printf("\n\n\n");
    printf("APRIL\t%d\n\n", year);
    printf("Sun\tMon\tTue\tWed\tThu\tFri\tSat\n");

    lineCount = 0;
    April = 30;

    for (x = 0; x < firstDayOfApril; x++)
    {
         printf("\t");
         lineCount++;
    }

    for (day = 1; day <= April; day++)

    {
         if (lineCount > 6)
         {
              printf("\n\n");
              lineCount = 0;
         }
         printf(" %d\t", day);
         lineCount++;
    }


    printf("\n\n\n");
    printf("MAY\t%d\n\n", year);
    printf("Sun\tMon\tTue\tWed\tThu\tFri\tSat\n");

    lineCount = 0;
    May = 31;

    for (x = 0; x < firstDayOfMay; x++)
    {
         printf("\t");
         lineCount++;
    }

    for (day = 1; day <= May; day++)

    {
         if (lineCount > 6)
         {
              printf("\n\n");
              lineCount = 0;
         }
         printf(" %d\t", day);
         lineCount++;
    }

      printf("\n\n\n");
    printf("JUNE\t%d\n\n", year);
    printf("Sun\tMon\tTue\tWed\tThu\tFri\tSat\n");

    lineCount = 0;
    June = 30;

    for (x = 0; x < firstDayOfJune; x++)
    {
         printf("\t");
         lineCount++;
    }

    for (day = 1; day <= June; day++)

    {
         if (lineCount > 6)
         {
              printf("\n\n");
              lineCount = 0;
         }
         printf(" %d\t", day);
         lineCount++;
    }


      printf("\n\n\n");
    printf("JULY\t%d\n\n", year);
    printf("Sun\tMon\tTue\tWed\tThu\tFri\tSat\n");

    lineCount = 0;
    July = 31;

    for (x = 0; x < firstDayOfJuly; x++)
    {
         printf("\t");
         lineCount++;
    }

    for (day = 1; day <= July; day++)

    {
         if (lineCount > 6)
         {
              printf("\n\n");
              lineCount = 0;
         }
         printf(" %d\t", day);
         lineCount++;
    }

    printf("\n\n\n");
    printf("AUGUST\t%d\n\n", year);
    printf("Sun\tMon\tTue\tWed\tThu\tFri\tSat\n");

    lineCount = 0;
    August = 31;

    for (x = 0; x < firstDayOfAugust; x++)
    {
         printf("\t");
         lineCount++;
    }

    for (day = 1; day <= August; day++)

    {
         if (lineCount > 6)
         {
              printf("\n\n");
              lineCount = 0;
         }
         printf(" %d\t", day);
         lineCount++;
    }

    printf("\n\n\n");
    printf("SEPTEMBER\t%d\n\n", year);
    printf("Sun\tMon\tTue\tWed\tThu\tFri\tSat\n");

    lineCount = 0;
    September = 30;

    for (x = 0; x < firstDayOfSeptember; x++)
    {
         printf("\t");
         lineCount++;
    }

    for (day = 1; day <= September; day++)

    {
         if (lineCount > 6)
         {
              printf("\n\n");
              lineCount = 0;
         }
         printf(" %d\t", day);
         lineCount++;
    }

    printf("\n\n\n");
    printf("OCTOBER\t%d\n\n", year);
    printf("Sun\tMon\tTue\tWed\tThu\tFri\tSat\n");


    lineCount = 0;
    October = 31;

    for (x = 0; x < firstDayOfOctober; x++)
    {
         printf("\t");
         lineCount++;
    }

    for (day = 1; day <= October; day++)

    {
         if (lineCount > 6)
         {
              printf("\n\n");
              lineCount = 0;
         }
         printf(" %d\t", day);
         lineCount++;
    }

    printf("\n\n\n");
    printf("NOVEMBER\t%d\n\n", year);
    printf("Sun\tMon\tTue\tWed\tThu\tFri\tSat\n");

    lineCount = 0;
    November = 30;

    for (x = 0; x < firstDayOfNovember; x++)
    {
         printf("\t");
         lineCount++;
    }

    for (day = 1; day <= November; day++)

    {
         if (lineCount > 6)
         {
              printf("\n\n");
              lineCount = 0;
         }

         printf(" %d\t", day);
         lineCount++;
    }

    printf("\n\n\n");
    printf("DECEMBER\t%d\n\n", year);
    printf("Sun\tMon\tTue\tWed\tThu\tFri\tSat\n");

    lineCount = 0;
    December = 31;

    for (x = 0; x < firstDayOfDecember; x++)
    {       printf("\t");
         lineCount++;
    }

    for (day = 1; day <= December; day++)

    {
         if (lineCount > 6)
         {
              printf("\n\n");
              lineCount = 0;
         }
         printf(" %d\t", day);
         lineCount++;
    }

            return 0;
    }
            

0
 
LVL 6

Expert Comment

by:gj62
ID: 8107139
This is by no means polished, but here's VERY QUICK reduction of the above code into something more manageable...

#include <stdio.h>
#include <string.h>

#define NUM_MONTHS 12

enum MonthNames
{ JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,NOV,DEC } MonthNames;            

typedef struct
{
  char name[15];
  int dayOfWeek;
  int numberOfDays;
}MONTH;

MONTH months[NUM_MONTHS] = {{"JANUARY",0,31},{"FEBRUARY",0,28},{"MARCH",0,31},
                            {"APRIL",0,30},  {"MAY",0,31},     {"JUNE",0,30},
                            {"JULY",0,31},   {"AUGUST",0,31},{"SEPTEMBER",0,30},
                            {"OCTOBER",0,31},{"NOVEMBER",0,30},{"DECEMBER",0,31}};


void calcDayOfWeek(int year)
{
  int i;
 
  /* just handle JAN & FEB separately...*/
  months[JAN].dayOfWeek = (((year - 1) * 365) + ((year - 1) / 4) - (year - 1 / 100) +  (year - 1 / 400)) % 7;
  months[FEB].dayOfWeek = (months[JAN].numberOfDays + months[JAN].dayOfWeek) % 7;

  /* leap year calculation */
  if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0))
    months[FEB].numberOfDays=29;
  else
    months[FEB].numberOfDays=28;

  for ( i=MAR;i<=DEC;++i)
  {
    months[i].dayOfWeek = (months[i-1].numberOfDays + months[i-1].dayOfWeek) % 7;
  }
 
}      

int main (void)
{
     int year;
     int lineCount;
     int day;
     int x,y;

     char keepGoing[10] = "Y";

     while( *keepGoing == 'Y' || *keepGoing == 'y')
     {
           printf("Please enter the year:\n");
       scanf ("%d", &year);
       
       calcDayOfWeek(year);
           

        /* could make this a function all its own too */
       for ( x=JAN; x<=DEC; ++x)
       {
         printf("%s\t%d\n\n", months[x].name, year);
         printf("Sun\tMon\tTue\tWed\tThu\tFri\tSat\n");

         lineCount = 0;

         for (y = 0; y < months[x].dayOfWeek; y++)
         {
           printf("\t");
           lineCount++;
         }

         for (day = 1; day <= months[x].numberOfDays; day++)
         {
           if (lineCount > 6)
           {
               printf("\n\n");
               lineCount = 0;
           }
           printf(" %d\t", day);
           lineCount++;
         }
           printf("\n\n\n");
       }


     printf("\n\nDo you want to print another calendar?:");
     scanf ("%s", keepGoing);

      }
      return 0;
}
0
 

Author Comment

by:dmuran
ID: 8107214
gj,
This looks lots better but unfortunately there are many things I haven't studied yet so I can't use it...
Thanks a lot ....

DM
0
 
LVL 6

Expert Comment

by:gj62
ID: 8107711
OK - if you need to know what they are, just ask...
0
 

Author Comment

by:dmuran
ID: 8132664
gj62....
Can I ask u another question here or I have to start new question???
I'm working on another program that needs to randomly generate 100 numbers in range of 1-999....
This is what i have so far but cant execute it ....

#include <stdio.h>

#define SIZE 100

int main (void)
{
    int number [SIZE];

    num = rand() % 999 + 1;

    for (i =0; i < SIZE; i++);
    {
      num = rand() % 999 + 1;

        if (max % 3 == 0 || max % 7 == 0)

          a [i] = - num;
        else
          a [i] = num;
      }

This should be the beginning of the program so once I get the numbers generated there are many other things to do which I think I can handle (eg. pring all odd and even values, find the smalles value, etc....)
Please let me know how this works, can you answer my question here or I have to start new question and post some points...I'm new to this so I dont know how it works...Thanks a lot

DM

         
0
 
LVL 6

Expert Comment

by:gj62
ID: 8132718
You should post another question, but here's something to get you started.

num, max, a[] and i are all not declared.  I don't know exactly what you are trying to accomplish because the code is incomplete.

You have to include stdlib.h to use rand().

Before you call rand(), initialize the generator with:

srand( (unsigned)time( NULL ) );

That will use the time of your machine as the seed to the random number generator.  If you seed it with the same number each time, the "random" numbers will be the same!

Do you want to fill the array called number with the random numbers?  If so you must change the loop to:

  for (i =0; i < SIZE; i++);
  {
     number[i] = rand() % 999 + 1;
  }

It seems like you don't want to store multiple of 3 or 7 - if so, you can just test the number and subract 1 like you are doing, but I don't know what max is.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
This video teaches users how to migrate an existing Wordpress website to a new domain.
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question