// This program prints addition and muiltiplication tables for
// the range of numbers entered. The numbers must be positive
// and the upper value of the range must be greater then the lower
// value of the range.
#include <iostream>
#include <iomanip>
using namespace std;
void Q = quit
int R = enterRange
int A = printAdditonTable
int m = printMultiplicationTable
int main()
{
char choice
int i, j, low = 0, high = 0;
cout << setprecision(0);
do {
cout << "\n\t\tArithmetic Table Printing\n" // Print menu.
<< "\tR = Enter Range\n"
<< "\tA = Print Addition Table\n"
<< "\tM = Print Multiplication Table\n"
<< "\tQ = Quit\n\n"
<< "Enter your choice: ";
cin >> choice;
cout << "\n\n";
}
return (0);
}
int enterRange(R)
{
int i, j, low = 0, high = 0;
cout << "Enter low number: "; // Get high and low numbers.
cin >> low;
cout << "Enter high number: ";
cin >> high;
if ((low >= 1) && (high > low) // If range is good, proceed.
&& (high < 32))
break; // Otherwise, process the error.
else if (high <= low) {
cout << "Error! High number must be greater than Low number.\n\n";
} else if (high <= 1) {
cout << "Error! High number must be greater than 1.\n\n";
}
else if (low <= 0) {
cout << "Error! Low number must be greater than 0.\n\n";
} else if (high > 31) {
}
high = 0;
low = 0;
}
int printAdditionTable(A)
{
int i, j, low = 0, high = 0;
if ((high == 0) || (low == 0)) { // Stop if we don't have
cout << "Error! Invalid range!\n"; // a good range.
break;
}
cout << " Addition Table\n"; // Print addition table.
for (i = 0; i <= (high - low) + 2; i++)
cout << "-----";
cout << "\n ";
for (i = low; i <= high; i++)
cout << setw(5) << i;
cout << "\n";
for (i = 0; i <= (high - low) + 2; i++)
cout << "-----";
cout << "\n";
for (i = low; i <= high; i++) {
cout << setw(2) << i << " |" ;
for (j = low; j <= high; j++)
cout << setw(5) << i+j;
cout << "\n";
}
}
int printMultipicationTable(M)
{
int i, j, low = 0, high = 0;
if ((high == 0) || (low == 0)) { // Stop if we don't have
cout << "Error! Invalid range!\n"; // a good range.
break;
}
cout << " Multiplication Table\n"; // Print multiplication table.
for (i = 0; i <= (high - low) + 2; i++)
cout << "------";
cout << "\n ";
for (i = low; i <= high; i++)
cout << setw(6) << i;
cout << "\n";
for (i = 0; i <= (high - low) + 2; i++)
cout << "------";
cout << "\n";
for (i = low; i <= high; i++) {
cout << setw(2) << i << " |" ;
for (j = low; j <= high; j++)
cout << setw(6) << i*j;
cout << "\n";
}
}
void quit(Q)
{
default : cout << "Enter \"R\", \"A\", \"M\", or \"Q\"";
}
} while ((choice != 'Q') && (choice != 'q'));
} // main()
} |