#include #include //for EXIT_SUCCESS, EXIT_FAILURE, and the exit function using namespace std; void factorial(int n); int main() { //Each expression in parentheses here in main is called an //"actual argument" of the function. factorial(4); //Pass the value 4 to the function. factorial(5); //Pass the value 5 to the function. int i {6}; factorial(i); //Create a copy of i and pass the copy to the function. factorial(i+1); //Pass the value 7 to the function. return EXIT_SUCCESS; //Inside of main is the only place you can do this. } void factorial(int n) //n is a "formal argument" or "parameter" of the function. { if (n < 0) { cerr << "argument " << n << " can't be negative.\n"; exit(EXIT_FAILURE); //Outside of main, exit instead of return. } int f {1}; for (int i {1}; i <= n; ++i) { f *= i; //means f = f * i } cout << "The factorial of " << n << " is " << f << ".\n"; }