|
From: Plunkett, M. <MPl...@ms...> - 2000-12-06 21:30:28
|
Don't know C++ too well, but you're running your factorial_cal without catching the return value. Try results = factorial_cal( number ); -----Original Message----- From: softnasolutions-ltd.fsbusiness.co.uk [SMTP:so...@so...] Sent: Wednesday, December 06, 2000 3:27 PM To: dev...@li... Subject: [Dev-C++] use of recursion Hi friends, I have just started learning C++ (i'm using a material from Cprogramming.com). I've tried to write a program to recursively calculate the factorial of a number but it doesn't work. Can someone please tell me what i've done wrong, Here is the code: #include <iostream.h> #include <stdlib.h> int factorial_cal(int results) { if (results>0) results=1*results; factorial_cal(results-1); return results; } int main() { int number; int results; cout<< "Enter a number for me to caculate its Factorial"<<endl; cin>>number; results=number; factorial_cal(results); cout<< " The factorial of "<<number<< " is "<<results<<endl; system("PAUSE"); return 0; } _______________________________________________ Dev-cpp-users mailing list Dev...@li... http://lists.sourceforge.net/mailman/listinfo/dev-cpp-users |