Help needed with a Project. ASAP Thanks

This is a discussion on Help needed with a Project. ASAP Thanks within the C Programming forums, part of the General Programming Boards category; The description for the following problem is that : I can not move my months in to the 3 dimentional ...

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    13

    Help needed with a Project. ASAP Thanks

    The description for the following problem is that :
    I can not move my months in to the 3 dimentional array.. I have done this coding already

    1.get year from keyboard
    2.generate a yearly calendar using a 3-dimensional array
    3.display this calendar three months at a time across the screen
    4.repeat this process (ask for another year and display that year’s calendar in the same way) until END is entered.


    This one works but one month at a time.. I want 3 months at a time and one after another for example
    months

    1 2 3
    4 5 6
    7 8 9
    10 11 12
    Code:
    #include <stdio.h>
    #include <conio.h>
    #include <string.h>
    
    int cal[6][7], day;
    
    void main(void);
    void cleararray(void);
    void generatecal(int);
    void dumparray(char []);
    
    void cleararray(void)
    {
        int row, col;
    
       for (row=0; row<=5; row++)
           for (col=0; col<=6; col++)
              cal[row][col] = 0;
    }
    
    void generatecal(int daysofmonth)
    {
        int row = 0, col, d;
    
        col = day;
        for (d=1; d<=daysofmonth; d++)
       {
           cal[row][col] = d;
          col++;
          if (col == 7)
          {
              row++;
             col = 0;
          }
       }
       /* assign the first day of the next month */
       day = col;
    }
    
    void dumparray(char month[])
    {
        int d, row, col;
    
       /* dump array content - generate output */
       for (d=1; d<=(21-strlen(month))/2; d++)
           printf(" ");
       printf("%s\n\n", month);
       printf("  S  M  T  W  R  F  S\n");
       for (row=0; row<=5; row++)
       {
           for (col=0; col<=6; col++)
             if (cal[row][col] == 0)
                 printf("   ");
             else
                  printf("%3d", cal[row][col]);
          printf("\n");
       }
    }
    
    void main(void)
    {
        int row = 0, col, m, year;
       char monthnames[12][10] = {"January", "February", "March", "April",
                                        "May", "June", "July", "August", "September",
                                "October", "November", "December"};
       int monthdays[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
       int firstdays[28] = {2, 3, 4, 5, 0, 1, 2, 3, 5, 6, 0, 1, 3, 4, 5, 6,
                                   1, 2, 3, 4, 6, 0, 1, 2, 4, 5, 6, 0};
    
       printf("Enter year: ");
       scanf("%d", &year);
       if (year % 4 == 0) monthdays[1] = 29;
        day  = firstdays[(year - 1901) % 28];
    
       for (m=0; m<=11; m++)
       {
           cleararray();
            generatecal(monthdays[m]);
            dumparray(monthnames[m]);
           getch();
       }
    }

    If anyone could please contct me Thank you..

    tagged by Salem
    Ok...

  2. #2
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    Just add 3 nested loops when printing the calendar, and make it increment by 3 instead of 1. You just have to input a command a third as often.

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    At the top of the forum is a thread called:
    << !! Posting Code? Read this First !! >>
    I strongly suggest you read it, along with the announcements.

    There are a number of problems with the code, here's one:

    >void main(void);
    Wrong, main returns an int, not void. And you should never prototype it.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Open-source Game Project
    By Glorfindel in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 03-24-2009, 01:12 AM
  2. Game Independent Anti-cheat Project Needs Programmers
    By GIA Project Lea in forum Projects and Job Recruitment
    Replies: 3
    Last Post: 09-15-2005, 07:41 PM
  3. How to add a file to a project in bloodshed.
    By Smeep in forum C++ Programming
    Replies: 4
    Last Post: 04-22-2005, 09:29 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21