// Operation table.  Mult, div, add, sub, mod.
// Suitable for children and programmers

#include <iostream>
#include <iomanip>

using namespace std;

void print_table (int size, char op);

int main () {

  int range;
  char op, ans;

  cout << "Make table of math operation" << endl;
  do {
    cout << "Enter upper range of table: ";
    cin >> range;

    cout << "Enter operation character (* / + - %): ";
    cin >> op;

    print_table(range,op);

    cout << endl << "Another? (y or n): ";
    cin >> ans;
  } while (ans == 'y');
}


//*******************************************************
void print_table (int size, char op) {
  int i, row, col;

  cout << endl << "  " << op << " ";
  for (i=1; i<=size; i++)    // header row (column headings)
    cout << setw(4) << i;
  cout << endl;
  cout << "   |";
  for (i=1; i<=size; i++)    //row of dashes
    cout << "----";
  cout << endl;

  for (row=1; row<=size; row++) {   //each row
    cout << setw(3) << row << '|';  //row number
    for (col=1; col<=size; col++)   //each column of row
      switch (op) {
      case '+': cout << setw(4) << row+col;
		break;
      case '-': cout << setw(4) << row-col;
		break;
      case '*': cout << setw(4) << row*col;
		break;
      case '/': cout << setw(4) << row/col;
		break;
      case '%': cout << setw(4) << row%col;
		break;
      }
    cout << endl;
  }
}






/*
Make table of math operation
Enter upper range of table: 10
Enter operation character (* / + - %): *

  *    1   2   3   4   5   6   7   8   9  10
   |----------------------------------------
  1|   1   2   3   4   5   6   7   8   9  10
  2|   2   4   6   8  10  12  14  16  18  20
  3|   3   6   9  12  15  18  21  24  27  30
  4|   4   8  12  16  20  24  28  32  36  40
  5|   5  10  15  20  25  30  35  40  45  50
  6|   6  12  18  24  30  36  42  48  54  60
  7|   7  14  21  28  35  42  49  56  63  70
  8|   8  16  24  32  40  48  56  64  72  80
  9|   9  18  27  36  45  54  63  72  81  90
 10|  10  20  30  40  50  60  70  80  90 100

Another? (y or n): y
Enter upper range of table: 12
Enter operation character (* / + - %): %

  %    1   2   3   4   5   6   7   8   9  10  11  12
   |------------------------------------------------
  1|   0   1   1   1   1   1   1   1   1   1   1   1
  2|   0   0   2   2   2   2   2   2   2   2   2   2
  3|   0   1   0   3   3   3   3   3   3   3   3   3
  4|   0   0   1   0   4   4   4   4   4   4   4   4
  5|   0   1   2   1   0   5   5   5   5   5   5   5
  6|   0   0   0   2   1   0   6   6   6   6   6   6
  7|   0   1   1   3   2   1   0   7   7   7   7   7
  8|   0   0   2   0   3   2   1   0   8   8   8   8
  9|   0   1   0   1   4   3   2   1   0   9   9   9
 10|   0   0   1   2   0   4   3   2   1   0  10  10
 11|   0   1   2   3   1   5   4   3   2   1   0  11
 12|   0   0   0   0   2   0   5   4   3   2   1   0

Another? (y or n): y
/*

