Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 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;
- 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";
- void enterRange2()
- {
- switch (choice) {
- case('R') :
- case('r') : 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;
- }
- void printAdditionTable3()
- {
- case('A') :
- case('a') : 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";
- }
- }
- void printMultipicationTable4()
- {
- case('M') :
- case('m') : 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 quit5()
- {
- case('Q') :
- case('q') : break;
- default : cout << "Enter \"R\", \"A\", \"M\", or \"Q\"";
- }
- } while ((choice != 'Q') && (choice != 'q'));
- } // main()
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement