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.
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. "; default:
cout << year << " isn't a leap year." << endl;
break;
}
return 0;
}
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