Click here to Skip to main content
Licence 
First Posted 17 Feb 2004
Views 50,903
Bookmarked 12 times

Leap Year

By | 17 Feb 2004 | Article
This code will calculate whether the year you enter is a leap year or not.

Introduction

This code will calculate whether the year you enter is a leap year or not.

Using the code

This code is VERY straightforward, no tricks here.

//#include "iostream.h"

int year;

int main()

{
    cout << "Please enter the current year: ";
    cin >> year;

    switch (year % 4)
    {
    case 0:
        if (year % 100 == 0)
        {
            cout << "\"Century\" years aren't leap years.";
            if (year % 400 == 0)
            {
                cout << "..unless divisible by 400.\n";
                cout << year << "'s a leap year!" << endl;
            }
            else
                cout << "  " << year << " isn't a leap year." << endl;
        }
        else
            cout << year << " is a leap year!" << endl;
        break;

    case 3:
        cout << "Next year is a leap year.  "; // Fall through...
    default:
        cout << year << " isn't a leap year." << endl;
        break;
    }
    return 0;
}

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

HackerBoy



United States United States

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralUnless your name is Brandon Quick... PinsussAnonymous16:43 19 Feb '04  
GeneralRe: Unless your name is Brandon Quick... Pinmemberslimtim18:48 19 Feb '04  
GeneralRe: Unless your name is Brandon Quick... PinmemberHackerBoy3:13 23 Feb '04  
QuestionHow About PinmemberLarry Antram23:24 18 Feb '04  
GeneralReally impressive PinmemberPatje21:32 18 Feb '04  
GeneralA simpler way PinmemberMark Focas17:08 18 Feb '04  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120517.1 | Last Updated 18 Feb 2004
Article Copyright 2004 by HackerBoy
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid