I'm trying to write a program to give the factorial of a number from the user. If you've read the www.cprogramming.com tutorial on recursion then you'll know why. The problem is that the compiler I'm using (Dev-C++) is giving errors for code I think is right... (in other words its wrong :P)
Heres the code:
(sorry if its too big but its not as if its a huge program...)Code:#include <iostream.h> //Generate factorial numbers int yournum; int final; int working; int main() { cin>>yournum; final=yournum; working=yournum-1; if(yournum<=0) { cout<<"Error sorry"; } else { factorial(); } cout<<"\nPress any key to exit"; cin.get(); return 0; } void factorial() { if(working<=0) { cout<<"Your number was !", yournum, " which equals ", final; return; } working=working-1; working*final=final; factorial(); }
There errors are line 21 which is "factorial();" and line 36 which is also "factorial();".
What am I doing wrong?? :S
Thanks....



LinkBack URL
About LinkBacks


