check for number of days as a fuction?

This is a discussion on check for number of days as a fuction? within the C++ Programming forums, part of the General Programming Boards category; hey guys; im pretty new at c++ and thus need help. Im looking to do a day check for a ...

  1. #1
    Registered User
    Join Date
    Jun 2002
    Posts
    3

    check for number of days as a fuction?

    hey guys;

    im pretty new at c++ and thus need help.

    Im looking to do a day check for a program i have wrote and it needs to validate the date and if necessary ask the user to enter it again. logic checks are needed i.e. day and month are consistent.

    it at all possible to write this as a fuction maybe?

    cheers scronge

  2. #2
    Registered User blight2c's Avatar
    Join Date
    Mar 2002
    Posts
    266
    my granddad always said, "if it's possible to skin a cat . . ."

  3. #3
    Seeking motivation... endo's Avatar
    Join Date
    May 2002
    Posts
    537
    Originally posted by blight2c
    my granddad always said, "if it's possible to skin a cat . . ."
    I dont get it

    Anyway to answer the question, here is a start. It checks that the number of days is appropriate for the month, however does not cater for leap years.
    Code:
    //uses a date object for simplicity
    bool checkDate( const Date& date )
    {
        static int daysInMonth[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
    
        if( date.day <= 0 || date.day > daysInMonth[ date.month -1 ] )
        {
            cout << "bad date, try again" << endl;
            return false;
        }
        return true;
    }

  4. #4
    Registered User
    Join Date
    Jun 2002
    Posts
    3
    thats brill mate, thx alot
    scronge

  5. #5
    Seeking motivation... endo's Avatar
    Join Date
    May 2002
    Posts
    537
    no problem, if you get stuck with pther parts just ask again

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. spell check in C using a dictionary file
    By goron350 in forum C Programming
    Replies: 10
    Last Post: 11-25-2004, 06:44 PM
  2. MFC: How do you check if a directory exists before creating?
    By BrianK in forum Windows Programming
    Replies: 5
    Last Post: 07-06-2004, 02:09 AM
  3. check if txt file
    By Boomba in forum C++ Programming
    Replies: 5
    Last Post: 06-16-2003, 08:43 PM
  4. Counting Number of days from year zero
    By wireless in forum C++ Programming
    Replies: 4
    Last Post: 06-16-2002, 08:31 AM
  5. while, sentinel, if, switch
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 11-11-2001, 11:50 PM

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