A room check has two useful outcomes: available or full. An if statement can handle the first condition; an else block supplies the alternative when that condition is false.
#include <iostream>
#include <string>
int main() {
int visitors = 6;
int limit = 9;
std::string status = "Pending";
if (visitors < limit) {
status = "Available";
} else {
status = "Full";
}
std::cout << status << "\n";
return 0;
}
Only one branch runs. else does not need its own condition: it means “otherwise” for the preceding if. Once the chosen block finishes, execution continues after the entire decision.
This differs from writing two independent if statements. Two independent conditions are both checked and might both be true. An if/else pair expresses mutually exclusive alternatives directly.
Pay attention to equality at the boundary. With visitors < limit, exactly reaching the limit belongs in the else branch. A room with no remaining capacity should not still report available. Reading the condition together with its alternative helps catch this kind of mistake.
The starter already decides which branch to enter. Your job is to give each branch its assignment. After Task 1, the below-capacity case should show its new status while the other cases still show "Pending". Task 2 fills those remaining cases through the single else branch.
A supplied for line repeats this decision with booked equal to 11, 12, and 13, while capacity stays 12. You will learn to write loops in the next section. Leave this probe unchanged here: your edits belong only inside the two decision blocks. The output label tells you which value was checked.
if block, assign "Places available" to status. The below-capacity probe should print Booked 11: Places available.else block, assign "Fully booked" to status. Both the exact-capacity and over-capacity probes should print that status for bookings of 12 and 13.Edit main.cpp, press Run to inspect the Console, then Submit to check these results.