Thread: extending a month calander to a year

  1. #1

    Question extending a month calander to a year

    i have made a code which allows a user to input the amount of days in a month and the start day and then displays a calander for that month. I now what to extend it to display each month of the year under neath each other. Any ideas how i would acomplish this?


    int i, n, day;
    printf("enter number of days in the month:");
    printf("Enter starting day of the week (1=Sun, 7=Sat):");
    printf(" S, M, T, W, T, F, S\n");
    for ( i=0; i<(day-1); i++ )
    printf(" ");
    for (i=1; i <= n ; i++)
    if (i==(9-day) ||i==(16-day) || i==(23-day) || i==(30-day))
    printf("%3d", i);
    return 0;

  2. #2
    Registered User
    Join Date
    Aug 2001
    well, you could have the function call itself 11 more times (to display twelve months, or 12 - whatever month it is you just entered. You would just have to change the input parameter to the last day of the month called plus 1 (as it follows that if thursday is the last day of april, friday has to be the first of may.

    Of course, the only way to really accomplish this is to rework your code so that you put all of it in a function (not main), and give that function the paremeters. Like:

    int cal(int days, int start_day){


  3. #3
    if i rewrote the code like below would this make it any easier to accomplish? Im new to programming so am learning from your help thanks very much!!

    #include <stdio.h>

    void PrintEmptyDays (int firstDay);
    void PrintDay (int currday);
    int isSaturday (int currDay, int firstDay);

    int main (void)
    int firstDay, daysInMonth;

    printf ("First day of month please? ");
    scanf ("%d", &firstDay);

    printf ("Number of days in month please? ");
    scanf ("%d", &DaysInMonth);

    printf ("Sun Mon Tue Wed Thu Fri Sat\n");

    PrintEmptyDays (firstDay);
    for (i = 1; i <= daysInMonth; i++)
    PrintDay (i);
    if (isSaturday(i, firstDay))
    printf ("\n");

    return 0;
    void PrintEmptyDays (int firstday)

    int isStaturday (int currDay, int firstDay)
    return 0;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Calendar Problem
    By wordup in forum C Programming
    Replies: 7
    Last Post: 10-29-2002, 03:36 PM
  2. error with code
    By duffy in forum C Programming
    Replies: 8
    Last Post: 10-22-2002, 09:45 PM
  3. cant get code to work
    By duffy in forum C Programming
    Replies: 13
    Last Post: 10-20-2002, 05:23 AM
  4. Printing weekday
    By sworc66 in forum C Programming
    Replies: 12
    Last Post: 09-13-2002, 07:03 AM
  5. HELP with starting out.
    By sworc66 in forum C Programming
    Replies: 4
    Last Post: 09-05-2002, 10:09 AM