A function is a named piece of work that a program can request. You have already used main: it is the function where this program begins. Now you will define another function and let main ask it for a result.
#include <iostream>
int daysInWeekend() {
return 2;
}
int main() {
int days = daysInWeekend();
std::cout << days << '\n';
return 0;
}
In int daysInWeekend(), the first int says the function produces an integer. daysInWeekend is its name. The empty parentheses mean this function takes no input values. The braces contain the statements to perform when it is called.
daysInWeekend() in main is a call. Execution enters that function. return 2; sends the integer back and immediately ends that call. The caller then stores the returned value in days and continues with its next statement.
Returning and printing are different jobs. Follow the value in this example: return 2; sends it back to main, which stores it in days, and only the std::cout statement displays it. You could use that same returned value in arithmetic or a condition without printing anything. Writing the helper's definition does not run it; execution reaches its body when main calls it.
Your starter already defines and calls standardCapacity, but its return value is a safe placeholder. Replace that value inside the helper. Leave the call and the supplied output statement unchanged. For now, place helper definitions above main so the compiler knows their names before seeing calls to them.
standardCapacity to return the integer 24. The existing call should print Capacity: 24.Edit main.cpp, press Run to inspect the Console, then Submit to check your work.