Boolean Data Type
In the previous step, the first player's move was implemented. In this lesson, we will implement the second player's move and add the ability to take turns.
The
bool type represents a Boolean data type that can take one of two values: true or false. Line 1, Char 1
Logical operations
Logical operations let you combine and modify these values to make decisions in a program. C# provides several logical operators for working with the
bool type:&&- Logical AND. Returns true if both operands are true.||- Logical OR. Returns true if at least one operand is true.!- Logical NOT. Inverts the logical value.
Logical AND
Line 1, Char 1
Logical OR
Line 1, Char 1
Logical NOT
Line 1, Char 1
Exercises
- A grandfather is a man (isMan) who has a child (manHasChildren), and that child also has children (childHasChildren). Write code for this expression.
Line 1, Char 1
- Write, call, and print the result of a function with the structure
bool IsParent(int countSons, int countDaughters), where countSons is the number of sons and countDaughters is the number of daughters.
Line 1, Char 1