title: "Recursive on All Control Paths" error when implementing factorial function
body: <p>For class I have an assignment:</p>
  <blockquote>
  <p>Write a C++ program that will output the number of distinct ways in which you can pick <code>k</code> objects out of a set of <code>n</code> objects (both <code>n</code> and <code>k</code> should be positive integers). This number is given by the following formula:</p>
  <p><code>C(n, k) = n!/(k! * (n - k)!)</code></p>
  <p>Your program should use two value-returning functions. The first one should be called <code>factorial</code> and should return <code>n!</code>.  The second function should be called <code>combinations</code> and should return <code>n!/(k! * (n - k)!).</code> Test your program for different values of <code>n</code> and <code>k</code> five times (count-controlled loop).</p>
  </blockquote>
  <p>I came up with a solution:</p>
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  int factorial(int);
  int combination(int, int);
  
  void main(void)
  {
      int objects, set_number, count; 
      count = 1; 
          while(count &lt;= 5)
          {
              cout &lt;&lt; &quot;Please enter in number of objects &quot;;
              cin &gt;&gt; objects; 
              cout &lt;&lt; &quot;Please enter in the number of Sets &quot;;
              cin &gt;&gt; set_number;
              count++;
          }
  
      cout &lt;&lt; &quot;The Factorial is &quot; &lt;&lt; factorial(set_number) &lt;&lt; &quot; &amp; the combination is &quot; &lt;&lt; combination &lt;&lt; endl;
      cout &lt;&lt; endl; 
  }
  
  // Factorial 
  int factorial(int set_number)
  {
      int cal;
      cal = set_number * factorial(set_number - 1);
      return cal; 
  }
  
  //  Combination
  int combination(int objects, int set_number)
  {
      int com_total, cal_set, cal_obj, min_sum, cal_min;
  
      cal_set = set_number * factorial(set_number - 1);
      cal_obj = objects * factorial(objects - 1);
      
      //n!/(k! * (n - k)!)
      min_sum = set_number - objects; 
      cal_min = min_sum * factorial(min_sum- 1);
      com_total = cal_set / (cal_obj * cal_min);
      return com_total; 
  }
  </code></pre>
  <p>...but I keep getting an error, that says;</p>
  <blockquote>
  <p>&quot;'factorial' : recursive on all control paths, function will cause runtime stack overflow;&quot;</p>
  </blockquote>
  <p>If someone could help me, I've been working on this for about an hour and I'm stumped!</p>