Help on book exercises.

I'm reading through "C++ without fear". You don't get answers for the exercises and I'm stuck on one so I can't look it up. I'm suppose to make a function that finds the factorial of a number. I'm probably looking over a simple way to do this, but I can't seem to think of any simple way to do it. So if anyone could help me that would be great.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
using namespace std;
int factorial(int a);

main (){
     int n=0;
     cout << "Please enter your number: ";
     cin >> n;
     cout << "The factorial of " << n << "is: " << factorial(n);
     
     system ("pause");
     return 0;
     }
     
     int factorial(int a){
         for (int i=1;i<=a;i++){
             //I don't know what to put here to find the factorial, at least nothing simple.
             }
             return a;
         
         }
Topic archived. No new replies allowed.