Logical Operators (AND, OR, NOT)
C++
Easy
3 views
Problem Description
Use logical operators to combine conditions.
Real Life: Like checking multiple conditions for decisions.
Step-by-Step Logic:
1. AND (&&): both must be true
2. OR (||): at least one must be true
3. NOT (!): reverses the condition
4. Print results of logical operations
Official Solution
void operator_q4_logical() {
bool isRaining = true;
bool haveUmbrella = false;
cout << "Is raining: " << isRaining << endl;
cout << "Have umbrella: " << haveUmbrella << endl;
cout << "Raining AND have umbrella: " << (isRaining && haveUmbrella) << endl;
cout << "Raining OR have umbrella: " << (isRaining || haveUmbrella) << endl;
cout << "NOT raining: " << (!isRaining) << endl;
}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!