Learn

Awesome! In this mini-lesson, we’ve added more operators to our toolbox:

  • &&: the and logical operator
  • ||: the or logical operator
  • !: the not logical operator

Instructions

1.

Optional: Let’s try a challenging problem that will put all your brain cells to the test.

Write a leap_year.cpp program that:

  1. Takes a year as input.
  2. Checks to see if the year is a four-digit number.
  3. Displays whether or not the year falls on a leap year.

There are 3 criteria that must be taken into account to identify a leap year:

  • If the year can be evenly divided by 4 then it is a leap year, however…
  • If that year can be evenly divided by 100, and it is not evenly divided by 400, then it is NOT a leap year.
  • If that year is evenly divisible by 400, then it is a leap year.

Take some time to research and brainstorm before starting to write the code!

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.
Already have an account?