Skip to Content
Logical Operators

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



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!

Folder Icon

Take this course for free

Already have an account?