A program can state an expectation directly instead of leaving it in a comment. There are two different moments at which C++ can check such expectations.
static_assert(condition, "message") checks a constant expression during compilation. A false condition prevents the program from compiling. This is useful for fixed configuration rules. assert(condition), from <cassert>, checks an internal expectation when execution reaches it in builds where assertions are enabled. A false assertion stops execution; it is not a way to ask a user to correct an ordinary input mistake.
#include <cassert>
#include <iostream>
constexpr int seats = 16;
static_assert(seats > 0, "A room needs seats");
int main() {
int reserved = 6;
assert(reserved <= seats);
std::cout << seats - reserved << '\n';
}
Both checks above succeed. Neither check produces a success message; the output comes from cout. Keep calculations and state changes outside assert. Assertions may be disabled, so essential behavior must never depend on evaluating their expressions.
The starter provides valid assertions around a simple shelf calculation. The first check requires a positive shelf count. The check inside freePlaces requires used to lie between zero and capacity. Once that condition holds, the unused places are the capacity left after subtracting the used places. We do not run deliberately failing assertions here: a stopped program would hide later Console probes. Read each supplied assertion before changing a value, and notice whether its condition is known at compile time or only after a calculation.
For expected failures such as “this book is already on loan,” return a status to the caller instead. A later section builds that recoverable path. Assertions are for assumptions the programmer believes should already be true.
Edit main.cpp; the supplied Console probes already call your code.
shelfCount to four while preserving the positive-count static_assert. Expect Configured shelves: 4.freePlaces, keeping its supplied precondition assertion. Expect Free places: 13.Use Run to inspect the Console, then Submit to check your work.