So far, helper definitions have appeared above main. Another arrangement puts a short declaration above main and the full definition below it. The compiler needs to know a function's interface before a call, but it does not need the whole body there.
#include <iostream>
int doubleCount(int count);
int main() {
std::cout << doubleCount(6) << '\n';
return 0;
}
int doubleCount(int count) {
return count * 2;
}
The first int doubleCount(int count); announces the return type, name, and parameter type. It ends with a semicolon and has no body. This is sometimes called a function prototype. The later definition supplies the body that performs the work.
Both must agree on the function's return type and parameter types. The declaration tells the compiler how to check the call in main: one integer goes in, and an integer comes back. It is not a call, because it includes the return type and parameter declaration.
There are two appearances of seatsForRows outside main, but only one place to write the calculation. The line above main ends in a semicolon and describes the function. The definition below main has braces and contains its work. Replace the temporary return value in that lower body; leave the declaration and both calls unchanged.
A declaration lets you organize the file without moving the program's entry point to the bottom. It does not replace a definition: a called function still needs its implementation. In this course, both remain in the same main.cpp file.
seatsForRows definition below main so it returns rows * 6, keeping the matching declaration above main. Expect Two rows: 12 and Four rows: 24.Edit main.cpp, press Run to inspect the Console, then Submit to check your work.