C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 02-08-2010, 08:30 PM   #1
Registered User
 
Join Date: Aug 2009
Posts: 10
C++ help

Code:
int main()
{ int num, factorial;
   num = 6;
   factorial = Fact(num);
   cout << num << "! = " 
           << factorial;
   return 0;
} // end main
int Fact (int num)
{  if (num == 0)
      return 1;
   else
      return num*Fact(num-1);
} //end Fact
I cant get this to to compile. What is supposed to be the output of this?
heredia21 is offline   Reply With Quote
Old 02-08-2010, 09:03 PM   #2
and the hat of sweating
 
Join Date: Aug 2007
Location: Toronto, ON
Posts: 3,425
Put the main() function at the bottom.
You also forgot to:
Code:
#include <iostream>
using namespace std;
__________________
"I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

"the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010
cpjust is offline   Reply With Quote
Old 02-08-2010, 09:10 PM   #3
Registered User
 
Join Date: Aug 2009
Posts: 10
Code:
#include <iostream>
using namespace std;



   int num, factorial;
   num = 6;
   factorial = Fact(num);
   cout << num << "! = " 
           << factorial;
   return 0;
} // end main
int Fact (int num)
{  if (num == 0)
      return 1;
   else
      return num*Fact(num-1);
} //end Fact
 int main()
This?
heredia21 is offline   Reply With Quote
Old 02-08-2010, 09:30 PM   #4
Registered User
 
jeffcobb's Avatar
 
Join Date: Dec 2009
Location: Henderson, NV
Posts: 887
Not even close:
Code:
#include <iostream>

using namespace std;


int Fact (int num)
{  if (num == 0)
      return 1;
   else
      return num*Fact(num-1);
} //end Fact


int main()
{ int num, factorial;
   num = 6;
   factorial = Fact(num);
   cout << num << "! = " 
           << factorial;
   return 0;
} // end main
It outputs "6! = 720" for whatever good that is...
__________________
C/C++ Environment: GNU CC/Emacs
Make system: CMake
Debuggers: Valgrind/GDB
jeffcobb is offline   Reply With Quote
Old 02-08-2010, 09:33 PM   #5
Registered User
 
Join Date: Aug 2009
Posts: 10
thanks alot
heredia21 is offline   Reply With Quote
Old 02-08-2010, 09:35 PM   #6
Registered User
 
jeffcobb's Avatar
 
Join Date: Dec 2009
Location: Henderson, NV
Posts: 887
Yeah but thats the last freebie.
__________________
C/C++ Environment: GNU CC/Emacs
Make system: CMake
Debuggers: Valgrind/GDB
jeffcobb is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump


All times are GMT -6. The time now is 12:20 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22