Im trying to do a exercise in one of my books and it wants me to use a function to get the factorial of a number entered by the user. Ive tried several different ways and they either get me numbers that make no sense or say if I entered 5, I would just get 25(which is what the code below does). Any help in the right direction would be great, thanks.

```
#include <iostream>
using namespace std;
int factorial(int n);
int main () {
int n;
cout << "Enter a number then press ENTER: ";
cin >> n;
cout << factorial(n) << " ";
cin.get();
return 0;
}
int factorial(int n) {
for (int i = n; i >= 1; i--) {
return n = n * i;
}
}
```