title: Coding for Factorials in C++ using classes
body: <p>Received the following assignment in my C++ OOP class. </p>
  
  <p>Convert the following procedural program, which calculates a Factorial, into a program that uses a class to calculate the factorial.</p>
  
  <pre><code>#include &lt;iostream.h&gt;
  
  int factorial(int);
  
  int main(void) {
      int number;
      cout &lt;&lt; "Please enter a positive integer: ";
      cin &gt;&gt; number;
  if (number &lt; 0)
      cout &lt;&lt; "That is not a positive integer.\n";
  else
      cout &lt;&lt; number &lt;&lt; " factorial is: " &lt;&lt; factorial(number) &lt;&lt; endl;
  }
  
  int factorial(int number) {
      int temp;
      if(number &lt;= 1) return 1;
      temp = number * factorial(number - 1);
      return temp;
  }
  </code></pre>
  
  <p>Use the Following Driver Program.  A Driver program means that the int main() ... is already written for you. You only need to create the class and add it to the code.</p>
  
  <p>HINT:  Look at the Name of the class used in the code below (factorialClass), and look at the method/function name used below (FactNum).. Your new class MUST use them...</p>
  
  <pre><code>int main(void) {
  
   factorialClass FactorialInstance;  //
  
   cout &lt;&lt; "The factorial of 3 is: " &lt;&lt; FactorialInstance.FactNum(3) &lt;&lt; endl;
  
   cout &lt;&lt; "The factorial of 5 is: " &lt;&lt; FactorialInstance.FactNum(5) &lt;&lt; endl;
  
   cout &lt;&lt; "The factorial of 7 is: " &lt;&lt; FactorialInstance.FactNum(7) &lt;&lt; endl;
  
   system("pause");  // Mac user comment out this line
  
  }
  </code></pre>
  
  <p>I've done OK on my own, but I'm getting a bunch of error messages and I'm not sure what I'm missing. I've found lots of other chunks of code online that create factorial programs easily, but I'm not sure how to integrate that with his preferred driver code. Here's what I've got so far below.  </p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  class factorialClass{
      int f, n; 
      public: 
      void factorialClass::FactorialInstance();
  {
  f=1;
  cout&lt;&lt;"\nEnter a Number:";
  cin&gt;&gt;n;
  for(int i=1;i&lt;=n;i++)
      f=f*i;
  }
  }
  
  int main(void) {
  
   factorialClass FactorialInstance;  //
  
   FactorialInstance.FactNum();
  
   cout &lt;&lt; "The factorial of 3 is: " &lt;&lt; FactorialInstance.FactNum(3) &lt;&lt; endl;
  
   cout &lt;&lt; "The factorial of 5 is: " &lt;&lt; FactorialInstance.FactNum(5) &lt;&lt; endl;
  
   cout &lt;&lt; "The factorial of 7 is: " &lt;&lt; FactorialInstance.FactNum(7) &lt;&lt; endl;
  
   system("pause");  // Mac user comment out this line
  }
  </code></pre>