Solved

Determining a leap year

Posted on 1998-04-20
7
354 Views
Last Modified: 2010-04-10
Does anyone have a small snip of code that determines if a year is a leap year.

Or explain the rules that goven what determines if a year is a leap year.  

Thanks
0
Comment
Question by:rock1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 2

Accepted Solution

by:
Slarti earned 10 total points
ID: 1162407
It's very simple: It's a leap year if the year number is divisible by 4. The exception is that if the year is divisible by 100, it is _not_ a leap year. The exception to that is that the year 2000 _will_ be a leap year (so will the year 3000 if you plan to live that long).

0
 
LVL 22

Expert Comment

by:nietod
ID: 1162408
I'm 99% sure--addmitidly not 100% sure that you missed one.  If the year is divisible by 400 it is a leap year (even though it is divisble by 100.)  Then If it is divisible by 2000, it is not a leap year (even though it is divisible by 400).  

Can anyone confirm that?
0
 

Author Comment

by:rock1
ID: 1162409
I did some more research on this.

Every 4 years is a leap year (1992, 1996, ...).  But, as an exception,
every 100 years is not a leap year (2100, 2200, ...).  But as an exception
to this exception, every 400 years is a leap year (2000, 2400, ...).

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 22

Expert Comment

by:nietod
ID: 1162410
Well we got three opinions now.  None completely agree with the other.  But does it matter?  Over what time span does this matter?  Most likely the only exception year that will matter is the year 2000.  If so, the question then is, is it a leap year.
0
 

Author Comment

by:rock1
ID: 1162411
Yes, 2000 is a leap year.  Because it is divisible by 400.

Basically,

If the year is divisble by 4 it is a leap year.
But as an exception, every 100 years is not a leap year ( 2100, 2200 )
However, every 400 years is a leap year.  So 2000, 2400 are leap years.

Here is a code chunk I grabbed from someone.
bool bLeap = !( nYear % 4 ) && ( ( nYear % 100) || !( nYear % 400 ));

0
 
LVL 2

Expert Comment

by:Slarti
ID: 1162412
This is probably true. I am not sure whether year 3000 is really a leap year. But, as nietod said, it doesn't really matter for any practical purpose.
0
 

Author Comment

by:rock1
ID: 1162413
3000 Would not be a multiple because even though it can be divided by 4 and a 100, it is not a multiple of 400.


0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
C++ standard library based binary archive format 6 108
computer science syllabus 3 102
c++ syntax question 9 58
Copy output image from TWindowsMediaPlayer 6 55
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question