C++ · ОСНОВЫ · LESSON 07

Two checks.

&& и || · about 12 minutes

Learning with progressRead the summary for free. To save the work, log in to the account.
STEP 1

How it works.

&& означает «и»: нужны оба условия. || означает «или»: хватит одного.

age >= 7 && age <= 12

✦ Read the condition from left to right: age at least 7 and not more than 12.

STEP 2

Try to understand.

Read the condition from left to right: age at least 7 and not more than 12.

int age = 9;
bool allowed = age >= 7 && age <= 12;
cout << allowed << endl;

✦ Compare this to the first one. Then do the cool job yourself.

IN-CLASS PRACTICE

Type the code yourself

Manually type the program from the sample. So you'll remember commands and brackets.

#include <iostream>
using namespace std;

int main() {
    int age = 9;
    bool allowed = age >= 7 && age <= 12;
    cout << allowed << endl;
    return 0;
}
Open the editor for class work
HOMEWORK

Solve it yourself

Create int points = 8. Save in bool passed check that points is from 5 to 10 inclusive, and output passed.

The answer is hidden. Use similar examples from the lesson notes.

Opening up your homework