Many orders use the same packaging fee. A default argument lets a caller omit that commonly repeated value while still allowing an explicit replacement.
#include <iostream>
int packedCost(int itemCents, int packingCents = 40) {
return itemCents + packingCents;
}
int main() {
std::cout << packedCost(300) << '\n';
std::cout << packedCost(300, 10) << '\n';
return 0;
}
= 40 in the parameter list provides a default. The first call supplies only the item price, so the function receives 40 for packingCents and returns 340. The second call explicitly supplies 10, replacing the default for that call and producing 310.
A default is not an instruction to overwrite every incoming argument. It is used only when an argument is missing. Defaults belong at the right-hand end of the parameter list: once a parameter has a default here, following parameters must also have defaults. A caller cannot leave a hole and then supply a later argument.
When using a separate declaration, put the default in the declaration visible to callers and do not repeat it in the definition. Your program instead defines the function above main, so its one parameter list is the right place.
Find feeCents in the function's parameter list, rather than in its body. The addition in the body already works; only the default fee needs changing. After your edit, the one-argument call should produce a different total. The two-argument call should keep its previous result because it supplies its own fee.
feeCents a default of 75. Expect Standard: 575 while the explicit-fee call still prints Custom: 520.Edit main.cpp, press Run to inspect the Console, then Submit to check your work.