Quote:
Originally posted by golfinguy4
A) I'd create a BigNum/BigFloat class to go along with this project. It'd make things very nice.
B) That recursive method has a couple of flaws. If it is a big number, it might lead to a stack overflow. Also, what about if the user asks for the factorial of a negative number? In your case, you have an eventual stack crash caused by infinite recursion.
The calling function for the factorial restricts factorials to positive numbers (or 0). I've changed both types to a const double to take care of number problems. I don't think I'll be factorializing any number big enough to cause a stack problem. I guess it doesn't hurt to make precautions, though.