Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
More Logical Operators | Conditional Statements
Introduction to C++
course content

Зміст курсу

Introduction to C++

Introduction to C++

1. Basics
2. Variables
3. Conditional Statements
4. Loops
5. Intro to Arrays

bookMore Logical Operators

In the previous task you checked if the variable is greater than the number, but what should we do if we want to check if two variables are bigger than certain numbers simultaneously? For example, we want to drive today if the tank isn’t empty and there’s no traffic jump.

When you need to combine conditions you can use the following logical operators:

So the code to the example above will look like this:

We use here the operator && (AND) since we want that all of our conditions hold.

Let’s take a look at another example. The employee gets the salary twice a week: on the 15th and 30th. The following code prints a message by day of the month if the worker receives the wage on that day.

We used in this code the operator || (OR) since we need to check if at least one of these conditions is true.

Завдання

Emma wants to go for a walk in the park. She can do this if the weather is good: the temperature is greater than 15 but less than 30 degrees Celsius. Write the program which accepts temperature from the user and prints the message if the weather is good today.

  1. Accsept the value from the user and store it to the variable temp.
  2. Write if statement which check if the the variable temp is greater than 15 and less than 30.
  3. Print the message "The weather is good today!" if the both conditions are true.

Please, don’t forget to type the semicolumn at the end of lines.

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 3. Розділ 3
toggle bottom row

bookMore Logical Operators

In the previous task you checked if the variable is greater than the number, but what should we do if we want to check if two variables are bigger than certain numbers simultaneously? For example, we want to drive today if the tank isn’t empty and there’s no traffic jump.

When you need to combine conditions you can use the following logical operators:

So the code to the example above will look like this:

We use here the operator && (AND) since we want that all of our conditions hold.

Let’s take a look at another example. The employee gets the salary twice a week: on the 15th and 30th. The following code prints a message by day of the month if the worker receives the wage on that day.

We used in this code the operator || (OR) since we need to check if at least one of these conditions is true.

Завдання

Emma wants to go for a walk in the park. She can do this if the weather is good: the temperature is greater than 15 but less than 30 degrees Celsius. Write the program which accepts temperature from the user and prints the message if the weather is good today.

  1. Accsept the value from the user and store it to the variable temp.
  2. Write if statement which check if the the variable temp is greater than 15 and less than 30.
  3. Print the message "The weather is good today!" if the both conditions are true.

Please, don’t forget to type the semicolumn at the end of lines.

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 3. Розділ 3
toggle bottom row

bookMore Logical Operators

In the previous task you checked if the variable is greater than the number, but what should we do if we want to check if two variables are bigger than certain numbers simultaneously? For example, we want to drive today if the tank isn’t empty and there’s no traffic jump.

When you need to combine conditions you can use the following logical operators:

So the code to the example above will look like this:

We use here the operator && (AND) since we want that all of our conditions hold.

Let’s take a look at another example. The employee gets the salary twice a week: on the 15th and 30th. The following code prints a message by day of the month if the worker receives the wage on that day.

We used in this code the operator || (OR) since we need to check if at least one of these conditions is true.

Завдання

Emma wants to go for a walk in the park. She can do this if the weather is good: the temperature is greater than 15 but less than 30 degrees Celsius. Write the program which accepts temperature from the user and prints the message if the weather is good today.

  1. Accsept the value from the user and store it to the variable temp.
  2. Write if statement which check if the the variable temp is greater than 15 and less than 30.
  3. Print the message "The weather is good today!" if the both conditions are true.

Please, don’t forget to type the semicolumn at the end of lines.

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

In the previous task you checked if the variable is greater than the number, but what should we do if we want to check if two variables are bigger than certain numbers simultaneously? For example, we want to drive today if the tank isn’t empty and there’s no traffic jump.

When you need to combine conditions you can use the following logical operators:

So the code to the example above will look like this:

We use here the operator && (AND) since we want that all of our conditions hold.

Let’s take a look at another example. The employee gets the salary twice a week: on the 15th and 30th. The following code prints a message by day of the month if the worker receives the wage on that day.

We used in this code the operator || (OR) since we need to check if at least one of these conditions is true.

Завдання

Emma wants to go for a walk in the park. She can do this if the weather is good: the temperature is greater than 15 but less than 30 degrees Celsius. Write the program which accepts temperature from the user and prints the message if the weather is good today.

  1. Accsept the value from the user and store it to the variable temp.
  2. Write if statement which check if the the variable temp is greater than 15 and less than 30.
  3. Print the message "The weather is good today!" if the both conditions are true.

Please, don’t forget to type the semicolumn at the end of lines.

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Секція 3. Розділ 3
Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
some-alt