Hi,

I am working on a program that asks a user to enter a # between 1 to 50 and finds the factorial of that. It uses recursive function to find it.

Here is what I got so far:

Code:

include <iostream>
using namespace std;
//function prototypes
int getNum();
int fact(int);
void printResult(int, int);
int main()
{
int num;
int ans;
num = getNum();
ans = fact(num);
printResult(num, ans);
cout << endl << endl;
}
int getNum()
{
int num;
cout << "\nEnter a number:";
cin >> num;
return num;
}
int fact(int num)
{
if (num == 0)
return 1;
else
return num * fact(num - 1);
}
void printResult(int num, int ans)
{
cout <<"\nfactorial of" << num << "is : " << ans;
}

Its not working, can some please help me solve this problem.

Thanks

edit: sorry, I have posted this again, because previously I accidentally posted on C section.