Advertisement
Guest User

Untitled

a guest
Apr 2nd, 2014
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.16 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. void Q = quit
  11. int R = enterRange
  12. int A = printAdditonTable
  13. int m = printMultiplicationTable
  14.  
  15.  
  16. int main()
  17. {
  18.    char choice
  19.   int i, j, low = 0, high = 0;
  20.   cout  << setprecision(0);
  21.   do {
  22.     cout << "\n\t\tArithmetic Table Printing\n"   // Print menu.
  23.          << "\tR = Enter Range\n"
  24.          << "\tA = Print Addition Table\n"
  25.          << "\tM = Print Multiplication Table\n"
  26.          << "\tQ = Quit\n\n"
  27.          << "Enter your choice: ";
  28.     cin >> choice;
  29.     cout << "\n\n";
  30.     }
  31.     return (0);
  32.     }
  33.    
  34.    
  35.    
  36.     int enterRange(R)
  37.     {
  38.     int i, j, low = 0, high = 0;
  39.      cout << "Enter low number: ";   // Get high and low numbers.
  40.                   cin  >> low;
  41.                   cout << "Enter high number: ";  
  42.                   cin  >> high;
  43.                   if ((low >= 1) && (high > low)   // If range is good, proceed.
  44.                        && (high < 32))  
  45.                     break;                         // Otherwise, process the error.
  46.                   else if (high <= low) {
  47.                     cout << "Error! High number must be greater than Low number.\n\n";
  48.                   } else if (high <= 1) {
  49.                     cout << "Error! High number must be greater than 1.\n\n";
  50.                    }
  51.                    else if (low <= 0) {
  52.                    cout << "Error! Low number must be greater than 0.\n\n";
  53.                   } else if (high > 31) {
  54.                   }
  55.                   high = 0;
  56.                   low = 0;
  57.                }
  58.                
  59.                
  60.       int printAdditionTable(A)
  61.      {
  62.      int i, j, low = 0, high = 0;
  63.      if ((high == 0) || (low == 0))  {       // Stop if we don't have
  64.                       cout << "Error! Invalid range!\n";    // a good range.
  65.                       break;    
  66.                     }                                    
  67.                    cout << "  Addition Table\n";            // Print addition table.
  68.                    for (i = 0; i <= (high - low) + 2; i++)
  69.                      cout << "-----";
  70.                    cout << "\n    ";
  71.                    for (i = low; i <= high; i++)
  72.                      cout << setw(5) << i;
  73.                    cout << "\n";
  74.                    for (i = 0; i <= (high - low) + 2; i++)
  75.                      cout << "-----";
  76.                    cout << "\n";
  77.                     for (i = low; i <= high; i++) {
  78.                       cout << setw(2) << i << " |" ;
  79.                       for (j = low; j <= high; j++)
  80.                         cout << setw(5) << i+j;
  81.                       cout << "\n";
  82.                     }
  83.               }
  84.              
  85.              
  86.     int  printMultipicationTable(M)
  87.      {    
  88.      int i, j, low = 0, high = 0;    
  89.        if ((high == 0) || (low == 0))  {       // Stop if we don't have
  90.                       cout << "Error! Invalid range!\n";    // a good range.
  91.                       break;    
  92.                     }                        
  93.                    cout << "  Multiplication Table\n";     // Print multiplication table.
  94.                    for (i = 0; i <= (high - low) + 2; i++)
  95.                      cout << "------";
  96.                    cout << "\n    ";
  97.                    for (i = low; i <= high; i++)
  98.                      cout << setw(6) << i;
  99.                    cout << "\n";
  100.                    for (i = 0; i <= (high - low) + 2; i++)
  101.                      cout << "------";
  102.                    cout << "\n";
  103.                     for (i = low; i <= high; i++) {
  104.                       cout << setw(2) << i << " |" ;
  105.                       for (j = low; j <= high; j++)
  106.                         cout << setw(6) << i*j;
  107.                       cout << "\n";
  108.                     }
  109.         }
  110.        
  111.        
  112.      void quit(Q)
  113.      {  
  114.       default : cout << "Enter \"R\", \"A\", \"M\", or \"Q\"";
  115.     }
  116.   } while ((choice != 'Q') && (choice != 'q'));
  117. } // main()
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement