I have the following code below that works. I however want the output to look different. How do i make the output look like so:
If the user enters the number 3, output:
factorial(3) returns 3*factorial(2)
factorial(2) returns 2*factorial(1)
factorial(1) returns 1
factorial(3) = 6
#include <iostream>
using namespace std;
unsigned long factorial(int number);
int main()
{
int x;
cout << "Enter a number" << endl;
cin >> x;
You can put a cout statement (with a combination of text and the use of the number variable value) into the if and else sections of the factorial function before the return line.
factorial(3) returns 3*factorial(2)
text( number )text number text( number-1 text
The base case would be a shorter statement.
text( number )text