Advertisement
Guest User

Untitled

a guest
Mar 31st, 2014
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.00 KB | None | 0 0
  1. // This program prints addition and muiltiplication tables for
  2. // the range of numbers entered. The numbers must be positive
  3. // and the upper value of the range must be greater then the lower
  4. // value of the range.
  5.  
  6. #include <iostream>
  7. #include <iomanip>
  8.  
  9. using namespace std;
  10.  
  11. int main()
  12. {
  13.   char choice;
  14.   int i, j, low = 0, high = 0;
  15.   cout  << setprecision(0);
  16.   do {
  17.     cout << "\n\t\tArithmetic Table Printing\n"   // Print menu.
  18.          << "\tR = Enter Range\n"
  19.          << "\tA = Print Addition Table\n"
  20.          << "\tM = Print Multiplication Table\n"
  21.          << "\tQ = Quit\n\n"
  22.          << "Enter your choice: ";
  23.     cin >> choice;
  24.     cout << "\n\n";
  25.    
  26.     void enterRange2()
  27.     {
  28.     switch (choice) {
  29.       case('R') :
  30.       case('r') : cout << "Enter low number: ";   // Get high and low numbers.
  31.                   cin  >> low;
  32.                   cout << "Enter high number: ";  
  33.                   cin  >> high;
  34.                   if ((low >= 1) && (high > low)   // If range is good, proceed.
  35.                        && (high < 32))  
  36.                     break;                         // Otherwise, process the error.
  37.                   else if (high <= low) {
  38.                     cout << "Error! High number must be greater than Low number.\n\n";
  39.                   } else if (high <= 1) {
  40.                     cout << "Error! High number must be greater than 1.\n\n";
  41.                    }
  42.                    else if (low <= 0) {
  43.                    cout << "Error! Low number must be greater than 0.\n\n";
  44.                   } else if (high > 31) {
  45.                   }
  46.                   high = 0;
  47.                   low = 0;
  48.                }
  49.      void printAdditionTable3()
  50.      {
  51.       case('A') :
  52.       case('a') :  if ((high == 0) || (low == 0))  {       // Stop if we don't have
  53.                       cout << "Error! Invalid range!\n";    // a good range.
  54.                       break;    
  55.                     }                                    
  56.                    cout << "  Addition Table\n";            // Print addition table.
  57.                    for (i = 0; i <= (high - low) + 2; i++)
  58.                      cout << "-----";
  59.                    cout << "\n    ";
  60.                    for (i = low; i <= high; i++)
  61.                      cout << setw(5) << i;
  62.                    cout << "\n";
  63.                    for (i = 0; i <= (high - low) + 2; i++)
  64.                      cout << "-----";
  65.                    cout << "\n";
  66.                     for (i = low; i <= high; i++) {
  67.                       cout << setw(2) << i << " |" ;
  68.                       for (j = low; j <= high; j++)
  69.                         cout << setw(5) << i+j;
  70.                       cout << "\n";
  71.                     }
  72.               }
  73.      void printMultipicationTable4()
  74.      {        
  75.       case('M') :
  76.       case('m') :  if ((high == 0) || (low == 0))  {       // Stop if we don't have
  77.                       cout << "Error! Invalid range!\n";    // a good range.
  78.                       break;    
  79.                     }                        
  80.                    cout << "  Multiplication Table\n";     // Print multiplication table.
  81.                    for (i = 0; i <= (high - low) + 2; i++)
  82.                      cout << "------";
  83.                    cout << "\n    ";
  84.                    for (i = low; i <= high; i++)
  85.                      cout << setw(6) << i;
  86.                    cout << "\n";
  87.                    for (i = 0; i <= (high - low) + 2; i++)
  88.                      cout << "------";
  89.                    cout << "\n";
  90.                     for (i = low; i <= high; i++) {
  91.                       cout << setw(2) << i << " |" ;
  92.                       for (j = low; j <= high; j++)
  93.                         cout << setw(6) << i*j;
  94.                       cout << "\n";
  95.                     }
  96.         }
  97.      void quit5()
  98.      {  
  99.       case('Q') :
  100.       case('q') : break;
  101.       default : cout << "Enter \"R\", \"A\", \"M\", or \"Q\"";
  102.     }
  103.   } while ((choice != 'Q') && (choice != 'q'));
  104. } // main()
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement