Hi everyone,this program prompts a user for a leap yr code and a day code resulting in an entire year's calendar.The result displays months one below another.Can some one tell me how to make it print 2 months next to each other,that is JAN FEB then MAR APRIL below them.

#include <stdio.h>

main()

 //int print_calendar(year,day_code,leap_year)
 //{
{

    int day_code,days_in_month,leap_year,day,month;
    do
    {
        printf("Enter day and leap year codes:");
        scanf("%d%d",&day_code,&leap_year);
    }

    while (day_code <0 || day_code >6);

    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("\t\nFebruary");
            days_in_month= leap_year ?29 :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 Thurs Fri Sat\n");
        /* advance printer to correct position for first date*/
        for(day =1;day <=1 +day_code*5;day++)
            printf("\t");
        /* 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("");
        }
        /*set day_code for next month to begin*/
		
        day_code =(day_code +days_in_month)%7;
		
    }
}

yeah, i could probably help you with this, but unfortunately you didnt use code tags, so it's all but completely unreadable.

next time, try this:

[code=c] your code goes here

[/code]

okay, someone added code tags for you.

for one thing, your program output is all messed up, even for one month at a time. it looks like you took the original code and made a stab at modifiyting it, then posted the broken result here?

i guess before we go any further, have you considered using the built-in calendar and date library C? its called <time.h> and chock full of useful stuff.

anyhow, if you're going to continue down this path the only way you can print multiple column of months is to calculate each of the month on any particular row at the same time. so you'll need multiple variables for each column. like "days_in_month1" and "days_in_month2"

i got kind of curious and wound up doing it myself. with three months in each row. you can see the output here as an example

You basically have to
1) create both months at the same time
or
2) use a 2d array and load the calendar into the array. When done, print the array.

sorry about these errors in the above program.
line 75 and line 84 respectively

printf(" ") not \t
 printf("\n")

@jephthah-Thank you,I will look into <time.h>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.