Leap Year Exercise

Hello! New to programming here and slowly making my way through the C++ course. I’m trying to work on the leapyear.cpp project.

  if (year > 999 && year < 1000) {
    if (year%4==0 && year%100==0 && year%400==0) {
      std::cout << year << " is a leap year \n";

This is how I originally thought of completing this–putting an if statement within an if statement. However, this does not output anything as noted in the code. Why is that?

Assuming that year is of type int, then your first if statement precludes there from being any year that would match. Years greater than 999 starts at 1000 and years less than 1000 starts at 999.

1 Like