All lessons

3. Decisions

Logical operators

0 of 5 activities0%

Reading 1

And, or, not

Open

&& means both sides must be true. || means at least one side is true. ! flips true to false and false to true.

Comparisons like x >= 0 && x <= 100 are common for ranges. Put each comparison in full — do not write 0 <= x <= 100; that is not how C++ chains work.

Parentheses help readability when you mix && and ||.

if (age >= 13 && age <= 19) {
    cout << "teen" << endl;
}

if (x < 0 || x > 100) {
    cout << "out of range" << endl;
}

if (!done) {
    cout << "still working" << endl;
}

Check 2

What && needs

Open

When is (a > 0 && b > 0) true?

Fill in 3

Or operator

Open

The operator that is true when at least one side is true is written

Try it 4

Teen check

Open

Sample age is 15. Change it to 12 and 20.

main.cpp
Loading editor…
Output will appear here.

Assignment 5

In range

Open

Read one integer x. If it is between 1 and 100 inclusive, print in. Otherwise print out. Exact words.

main.cpp
Loading editor…