// multTable.cpp   Example of multiplication table
// Illustrates using nested for loops to make a 2-d table in C++

#include <iostream>
using namespace std;

#include <iomanip>


#define LIMIT 10


// A function that prints a line like this:
// ---++---+---+---+---+---+....
// with limit + 1 columns

void  printLineAcross(int limit)
{
  cout << "---++";
  for (int i = 1; i<=limit; i++)
    cout << "---+";
  cout << endl;
}

// A function to print a line like this:
// ===++===+===+===+===+===+....
// with limit + 1 columns

void  printDoubleLineAcross(int limit)
{
  cout << "===++";
  for (int i = 1; i<=limit; i++)
    cout << "===+";
  cout << endl;
}

// Note: would it be nicer if we had a single function: 
// printLineAcross(int limit, char c) that we could call as either:
//    printLineAcross(limit, '-');  or printLineAcross(limit, '='); ? 
// Then we could also do: printLineAcross(limit, '*'); for example...
// I'll leave that to the student as an exercise... :-)

int main(void)
{
  int i,j;

  /* print column header */

  cout << "           Multiplication Table          " << endl;

  printLineAcross(LIMIT);

  cout << " x ||" ;
  for (i = 1; i <=  LIMIT; i++)
    {
      cout << setw(3) << i << "|";
    }
  cout << endl;

  printDoubleLineAcross(LIMIT); 

  /* print column header */

  for (i = 1; i <=  LIMIT; i++) // i counts down the table
    {
      // print out first column
      cout << setw(3) << i << "||" ;

      // print rest of row.  Each table entry is i times j
      for (j = 1; j <=  LIMIT; j++) // j counts across the table
	{
	  cout << setw (3) << i * j << "|";
	}

      cout << endl;            // a newline to end the column
      printLineAcross(LIMIT);  // now another line of dashes
    }

  return 0;
}

