Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Apprendre Expressions Booléennes | Autres Types de Données et Concepts
Types de Données C++

bookExpressions Booléennes

You can also combine boolean statements. For example, the player is alive in a game while his health_value > 0 AND stamina_value > 0. You can write an expression like this in C++ using the and operator:

main.cpp

main.cpp

copy
12345678910
#include <iostream> int main() { short health_value = 50; short stamina_value = 70; if (health_value > 0 and stamina_value > 0) std::cout << "Player is alive!"; }

Let's look at the and operator in greater detail. It returns true if both statements are true. If at least one statement is false, the and operator will return false.

And if you want the player to have health_value > 0 OR stamina_value > 0 you can use the or operator.

main.cpp

main.cpp

copy
12345678910
#include <iostream> int main() { short health_value = 0; short stamina_value = 70; if (health_value > 0 or stamina_value > 0) std::cout << "There is still health or stamina left!"; }
question mark

Which statements about the and and or operators in C++ are correct?

Select all correct answers

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 4. Chapitre 2

Demandez à l'IA

expand

Demandez à l'IA

ChatGPT

Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion

bookExpressions Booléennes

Glissez pour afficher le menu

You can also combine boolean statements. For example, the player is alive in a game while his health_value > 0 AND stamina_value > 0. You can write an expression like this in C++ using the and operator:

main.cpp

main.cpp

copy
12345678910
#include <iostream> int main() { short health_value = 50; short stamina_value = 70; if (health_value > 0 and stamina_value > 0) std::cout << "Player is alive!"; }

Let's look at the and operator in greater detail. It returns true if both statements are true. If at least one statement is false, the and operator will return false.

And if you want the player to have health_value > 0 OR stamina_value > 0 you can use the or operator.

main.cpp

main.cpp

copy
12345678910
#include <iostream> int main() { short health_value = 0; short stamina_value = 70; if (health_value > 0 or stamina_value > 0) std::cout << "There is still health or stamina left!"; }
question mark

Which statements about the and and or operators in C++ are correct?

Select all correct answers

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 4. Chapitre 2
some-alt