An event rule may depend on more than one fact. A guest might need both a booking and a badge. Another rule might accept either a booking or a walk-in pass. Logical operators combine boolean answers.
| Operator | Read as | True when |
|---|---|---|
&& | AND | Both sides are true |
|| | OR | At least one side is true |
! | NOT | The following condition is false |
#include <iostream>
int main() {
bool booked = true;
bool hasBadge = false;
bool admitted = booked && hasBadge;
bool needsBadge = !hasBadge;
std::cout << std::boolalpha;
std::cout << admitted << "\n";
std::cout << needsBadge << "\n";
return 0;
}
This prints false and true. The first result needs two true facts, but hasBadge is false. The second reverses that false value. NOT creates an opposite answer; it does not change the stored hasBadge value.
C++'s OR includes the situation where both sides are true. It does not mean “exactly one.” Write two vertical bars for || and two ampersands for &&; the single-character operators have different purposes.
You can combine comparisons too, such as (age >= 12) && (age <= 17). Parentheses around each comparison make the two questions easy to see. Repeat age in both comparisons: mathematical shorthand such as 12 <= age <= 17 does not express a range test in C++. C++ would first compare 12 with age, then compare that boolean result with 17.
For &&, C++ skips the right side when the left is false; for ||, it skips the right side when the left is true. This is called short-circuit evaluation.
The starter gives you the facts separately: whether the visitor registered, has a badge, or holds a walk-in pass. The three result variables ask different questions about those facts. Replace their temporary values with logical expressions so that a change to a fact would also change the relevant answer.
ready with registered && hasBadge. Expect Ready: true.eligible using OR between registered and walkIn. Expect Eligible: true.needsRegistration using NOT on registered. Expect Needs registration: false.Edit main.cpp, press Run to inspect the Console, then Submit to check these results.