Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created December 14, 2020 15:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codecademydev/d80a49b40c5f50db91f2925eadbe896c to your computer and use it in GitHub Desktop.
Save codecademydev/d80a49b40c5f50db91f2925eadbe896c to your computer and use it in GitHub Desktop.
Codecademy export
#include <iostream>
int main() {
int year;
bool leapyear = false;
std::cout << "Please type in a year after 999 AD: ";
std::cin >> year;
if (year < 1000) {
std::cout << "Too early! Please try again.";
} else {
if (year % 400 == 0) {
leapyear = true;
} else if (year % 100 == 0) {
leapyear = false;
} else if (year % 4 == 0) {
leapyear = true;
} else {
leapyear = false;
}
}
if (leapyear) {
std::cout << year << " is a leap year.\n";
} else {
std::cout << year << " is not a leap year.\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment