Program showing if a year its leap year or not.

This is a discussion on Program showing if a year its leap year or not. within the C++ Programming forums, part of the General Programming Boards category; I need to make a program that can shows if it a year is leap year or not, I couldn't ...

  1. #1
    Registered User
    Join Date
    Sep 2008
    Posts
    37

    Question Program showing if a year its leap year or not.

    I need to make a program that can shows if it a year is leap year or not, I couldn't understand exactly what my teacher said because of his accent but I think he said this:

    "If the Input is four digits number integer tell if its leap year or not."

    This is the only Programming class i have to take and Is part of my course, I'm studying electronics engineering but my Teacher can't speak English well.

    Where can I see code examples like this one or if you can post the code i can read throught it and analize it. This won't be graded is just practice.

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,328
    Figure out how you'd solve it in real life. If I asked you, "Was 1048 a leap year? How about 1900? How about 2800? What about 7653?" How would you answer those questions?

    Once you've figured out the algorithm for solving those questions by hand (or in your head) all you have to do is apply that algorithm to your code.

  3. #3
    Registered User
    Join Date
    Sep 2008
    Posts
    10
    A leap year has a property that it's divisible by 4. Divisibility by 4 means that you can check for the last two digits (the least significant) to be divisible by 4 as well.

    That's what you need to implement .... Check if a number is divisible by 4 .... If it is, then it's a leap year otherwise not .....

  4. #4
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    Quote Originally Posted by gvkalra View Post
    That's what you need to implement .... Check if a number is divisible by 4 .... If it is, then it's a leap year otherwise not .....
    It's not as straight forward as that: link

    Nor will we write the code for you to
    Quote Originally Posted by Cyberman86 View Post
    analize
    QuantumPete
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    So, the rule is:
    A year is a leap year if it is divisiible by 4, not divisible by 100 unless it is also an even 400 year (so year 2000 was a leap-year, 1900 was not).

    To be calendarically correct, you would also have to take into account that some hundreds of years ago, there were no leap-years. But I think we can ignore that for now - and that is why the date in September (I think) some 3-400 years ago went forward about 11 days.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #6
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    Quote Originally Posted by matsp View Post
    So, the rule is:
    and that is why the date in September (I think) some 3-400 years ago went forward about 11 days.
    In fact it was a little more recent than that in some places: The October Revolution was actually in November according to our Gregorian Calendar.

    QuantumPete
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Leap Year Problems
    By jc99 in forum C Programming
    Replies: 13
    Last Post: 06-21-2009, 04:02 AM
  2. Writing a program to make a calendar
    By Northstar in forum C Programming
    Replies: 17
    Last Post: 11-07-2007, 10:34 AM
  3. Help with leap year program.
    By IxTanGxI in forum C Programming
    Replies: 8
    Last Post: 02-20-2006, 07:49 PM
  4. Missing something in dayofweek program
    By s_ny33 in forum C Programming
    Replies: 2
    Last Post: 11-15-2005, 09:34 AM

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