Sorry, I thought that would happen. (was in a hurry.)
Here goes.....
/* Finds the factorial of a number */
#include <iostream.h>
typedef long int lint;
lint factorial(lint x, lint xdown);
int main()
{
lint x;
lint y;
int choice;
start:
cout << "which number do you want to find the factorial of?: ";
cin >> x;
y = factorial(x, x-1);
cout << "\nthe factorial of " << x << " is " << y;
cout <<"\ndo you want to play again? (0 for no, 1 for yes): ";
cin >> choice;
if(choice == 0)
return 0;
else
goto start;
return 0;
}
lint factorial(lint x, lint xdown)
{
if (xdown < 1)
return x;
else
factorial(x*xdown,xdown - 1);
}
Using function recursion, the program finds the factorial of a number ... (6 * 5 * 4 * 3 ....)
But, after the number 16, the return number becomes too big for long integer, and flips over. When I put in float or double the program ends with "stack underflow" error.
I was wondering if there was a way around this
(is that enough info?) =-) RSTR
rstr@spacemail.com