/* factorial10.cpp is a driver program to test the Factorial 
 * function.  It computes any number of factorials.
 * 
 ************************************************************/

#include <iostream.h>      	     // cin, cout, <<, >>

int Factorial(int n);

int main()
{
   for (;;)
   {
      cout << "To compute n!, enter n (a negative number to quit): ";
      int theNumber;
      cin >> theNumber;

      if (theNumber < 0) break;

      cout << theNumber << "! = "
           << Factorial(theNumber) << "\n\n";
   }

   return 0;
}

/*** Insert the #include directive and the definition of
     Factorial() from Figure 3.8 here. ***/

/* Factorial computes the factorial of a nonnegative integer. 
 *     
 * Receive:      n, an integer
 * Precondition: n is nonnegative
 * Return:       n!
 *************************************************************/

#include <cassert>             // assert()

int Factorial(int n)
{
   assert(n >= 0);

   int product = 1;

   for (int count = 2; count <= n; count++)
      product *= count;

   return product;
}


