A function becomes more useful when it can work with values chosen by its caller. A parameter names an input inside the function. An argument is the actual value supplied in a call.
#include <iostream>
int travelMinutes(int stops, int minutesPerStop) {
return stops * minutesPerStop;
}
int main() {
std::cout << travelMinutes(3, 8) << '\n';
std::cout << travelMinutes(5, 8) << '\n';
return 0;
}
stops and minutesPerStop are parameters. Each needs its own type. The comma separates them. In the first call, 3 becomes the value of stops and 8 becomes the value of minutesPerStop. The function returns their product. The second call repeats the same rule with a different stop count.
Arguments match parameters by position, not by name. You can pass a literal such as 3, a variable, or a calculated expression. These integer parameters receive copies of the supplied values. A later lesson will explore what that means for local changes.
Your totalCents helper takes a quantity and a unit price measured in cents. Using integer cents keeps this small calculation exact without introducing decimal formatting. The supplied calls try two quantities, so write a rule using both parameters rather than one fixed answer.
Leave the two output statements in main as they are. Replace the temporary return value inside totalCents, using the parameter names in your calculation. When you run it, compare both lines: changing the quantity should change the result without requiring a second version of the function.
The diagram follows one call from arguments to parameter copies to the returned value. It uses addition to keep the value flow separate from your price calculation.
For add(4, 7), the first argument initializes the int parameter a and the second initializes the int parameter b. The function returns a + b, so the caller receives 11; it is not automatically printed. Your multiplication helper follows the same call-and-return pattern.
totalCents return quantity * unitCents. The supplied calls should print Three: 375 and Five: 625.Edit main.cpp, press Run to inspect the Console, then Submit to check your work.