A name is not automatically available everywhere in a program. Its scope is the region where code can use it. A variable declared in a block is local to that block, starting at its declaration. Parameters are available throughout the function body; each call receives its own parameter objects.
You have already met this boundary in loops: a counter declared in a for header cannot be used after the loop. Likewise, a variable declared inside an if block cannot be used after that block. To update a value that later code needs, declare it in the surrounding block, as you did with the decision lessons' notice variables.
#include <iostream>
int addBuffer(int minutes) {
int buffered = minutes + 5;
return buffered;
}
int main() {
int minutes = 20;
std::cout << addBuffer(minutes) << '\n';
std::cout << minutes << '\n';
return 0;
}
The output is 25 and then 20. The minutes parameter and the minutes variable in main are separate values, even though they share a name. The call copies the argument's value into its parameter. The local buffered variable exists only inside addBuffer; returning its value lets the caller receive the result without gaining access to that local name.
Changes to an ordinary int parameter affect its copy, not the original argument. If a caller wants to keep a returned result, it must assign that result to a variable. Simply calling a function does not replace the caller's variable.
In the starter, adjusted currently receives the same value as seats. Change its initializer to account for the seven reserved seats. The existing return adjusted; then sends that calculation back. Compare the two output lines: Remaining shows the helper's result, while Original reads the unchanged variable in main. You do not need to move adjusted outside the helper to use its returned value.
afterReservation, initialize the local adjusted value to seats - 7. Expect Remaining: 23 followed by Original: 30.Edit main.cpp, press Run to inspect the Console, then Submit to check your work.