# Calendar Program question for gj62

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;

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++;
}

}
}

###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Author Commented:
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 Commented:
gj62....
It works good, thanks a lot....I'll make sure to put more points next time....

Thanks...

DM
0
Commented:
Glad I could help - post again if you run into problems...
0
Author Commented:
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
Commented:
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 Commented:
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
Commented:
OK - if you need to know what they are, just ask...
0
Author Commented:
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
Commented:
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
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Development

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.