A program using a loop

// Author: Karl Abrahamson
// Date:   01/12/00
//
// This program prints a table of factorials,  up to
// a number given by the user.

#include <iostream>
#include <iomanip>
using namespace std;

///////////////////////////////////////////////////////////
//                   factorial
///////////////////////////////////////////////////////////
// factorial(n) is the factorial of n, which is
// 1x2x...xn.
///////////////////////////////////////////////////////////

long factorial(int n)
{
  long total = 1;
  int k = 2;
  while(k <= n) {
    total = total * k;
    k++;
  }
  return total;
}

///////////////////////////////////////////////////////////
//                   main
///////////////////////////////////////////////////////////

int main()
{
  int n, limit;
  cout << "How far should the table of factorials go? ";
  cin >> limit;
  cout << "    n          n!\n";
  cout << "-----    --------\n";
  n = 0;
  while(n <= limit) {
    cout << setw(5) << n << setw(12) << factorial(n) << endl;
    n++;
  }
  return 0;
}

Notes on the program

// Author: Karl Abrahamson
// Date:   01/12/00
//
// This program prints a table of factorials,  up to
// a number given by the user.
This program uses setw, and to use that we must include iomanip.h.
#include <iostream>
#include <iomanip>
using namespace std;

///////////////////////////////////////////////////////////
//                   factorial
///////////////////////////////////////////////////////////
// factorial(n) is the factorial of n, which is
// 1x2x...xn.
///////////////////////////////////////////////////////////
The loop starts at while. Notice the parentheses around the condition, which are required. Notice that the loop control variables (total and k) are initialized before entering the loop, and that k is incremented each time around the loop to ensure that eventually the loop will stop.
long factorial(int n)
{
  long total = 1;
  int k = 2;
  while(k <= n) {
    total = total * k;
    k++;
  }
  return total;
}

///////////////////////////////////////////////////////////
//                   main
///////////////////////////////////////////////////////////

int main()
{
  int n, limit;
  cout << "How far should the table of factorials go? ";
  cin >> limit;
  cout << "    n          n!\n";
  cout << "-----    --------\n";
  n = 0;
Here is another loop. The setw elements set the width for output, so that n will be shown in 5 spaces and factorial(n) will be shown in 12 spaces, padded with blanks on the left if necessary.
  while(n <= limit) {
    cout << setw(5) << n << setw(12) << factorial(n) << endl;
    n++;
  }
  return 0;
}