I suppose the question was about output formatting. OP's code gives this output:
Enter a number (0 to exit) and press ENTER: 5
Factorial(5) = 5*4*3*2*1 = 120
If the printing was all done at one line, the output would be:
Code:
cout << "Factorial(" << n << ") = " << get_factorials(n, b);
Enter a number (0 to exit) and press ENTER: 5
5*4*3*2*1 = Factorial(5) = 120
It is not the unused argument that makes any difference, but that the outputting is all one chained cout << call.
I'm not sure whether you'd get the same results with all compilers and compiler settings, but the cout << call would first evaluate function calls in the chain, and as get_factorials - as a side-effect - is also outputting to cout, this would be printed first (as in the second one-line example).
Wouldn't simply writing cout << get_factorials(n) as a separate statement solve the problem?
Or rather avoiding "couting" side-effects altogether, by letting each function perform one task:
Code:
//function's job is to print a factorial in a specially formatted way
//function doesn't return anything, so you won't be tempted to call it like
//cout << ... << print_formatted_factorial(n);
void print_formatted_factorial(int max)
{
cout << "Factorial(" << max << ") = ";
for (int i = 1; i < max; ++i) {
cout << i << "*";
}
cout << max << " = " << factorial(max) << '\n';
}
//function's job is to calculate a factorial
int factorial(int n)
{
int fac = 1;
for (int i = 2; i <= n; ++i) {
fac *= i;
}
return fac;
}