Thread: C++ calendar HELP!!!

  1. #1
    Registered User
    Join Date
    Nov 2004
    Posts
    8

    Unhappy C++ calendar HELP!!!

    HI i just started learning C++ in the past month. I need help on writing a functino to calculate the first day of the month from the input year. I have no idea where to start, this counter-controlled loop is killin me, it says write a counter-controlled loop whose counter represents eacy year between 1900 and the input year - 1. could somebody show me a function to help me out please!!

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Code:
    for ( y = 1900 ; y < inputyear ; y++ ) {
        // do something
    }
    Without leap years, the first day of January each year advances by one day.
    So 1/1/1900 was Monday, so 1/1/1901 was Tuesday.
    And so on until you've counted how many years you want to.

  3. #3
    Registered User
    Join Date
    Nov 2004
    Posts
    8

    Lightbulb C++ calendar

    So if i did:
    int calcDay(int month, int year)
    {
    int day=1;
    for(y=1900;y< year; y++)
    {
    if (isLeap(year))
    day = day + 366;
    else
    day = day = 365;
    day = day % 7;
    }
    }

    it should calculate the day from the input year right??

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Yeah, something like that

  5. #5
    Registered User
    Join Date
    Nov 2004
    Posts
    8
    ok so now that i got that...how bout the function to output the body of a calendar. something like?

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > how bout the function to output the body of a calendar
    30 days hath september...
    Just more loops, and knowing how many days there are in each month

  7. #7
    Registered User
    Join Date
    Sep 2004
    Posts
    719
    while we're on the subject, i was wondering what more advanced programmers would think of this function
    Code:
    int daysInMonth(int year, int month)
    {
        Date temp(year, month, 1);
        switch(month)
        {
            case 2:
                if(temp.isLeap())
                    return 29;
                else
                    return 28;
            case 4:
            case 6:
            case 9:
            case 11:
                return 30;
            default:
                return 31;
                    
        }       
        return 0;
    }
    i seem to have GCC 3.3.4
    But how do i start it?
    I dont have a menu for it or anything.

  8. #8
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    if it has to work for any year....

    To correct the calendar in 1582 10 days were arbitrarily omitted, 1582 October 4th being followed by 1582 October 15th.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Writing a program to make a calendar
    By Northstar in forum C Programming
    Replies: 17
    Last Post: 11-07-2007, 11:34 AM
  2. how to convert from solar calendar to lunar calendar??
    By zaracattle in forum C++ Programming
    Replies: 7
    Last Post: 11-30-2006, 07:17 AM
  3. calendar program for linux
    By *ClownPimp* in forum Tech Board
    Replies: 1
    Last Post: 10-01-2005, 02:31 AM
  4. Calendar Program. What am I doing wrong?
    By Sektor in forum C++ Programming
    Replies: 3
    Last Post: 01-17-2004, 11:39 PM
  5. writing a calendar program help please!!!
    By Newbie2006 in forum C Programming
    Replies: 7
    Last Post: 11-20-2002, 07:36 PM