Advertisement
TheWhiteFang

Tutorial 2 section A part D

Nov 2nd, 2014
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.87 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.         int value = 0;
  8.         while (1){
  9.             cout << "Enter a number between 1 & 20: ";
  10.             while (!(cin >> value)){
  11.                 cout << "Ending program. only integer values between 1 and 20 accepted" << endl;
  12.                 cin.clear(); //clear internal error flags
  13.                 cin.ignore(numeric_limits<streamsize>::max(), '\n');
  14.                 return 0;
  15.  
  16.             }
  17.             if (value > 0 && value <= 20){
  18.  
  19.  
  20.                 int i = 0; int j = 0;
  21.                 int count = 1;
  22.  
  23.                 for (i = 0; i < value; i++)
  24.                 {
  25.                     for (j = 0; j < value; j++)
  26.                     {
  27.                         cout << count << "\t";
  28.                         count++;
  29.                     }
  30.  
  31.                     cout << endl;
  32.                 }
  33.             }
  34.             else{
  35.                 cout << "Ending program. Only integer values between 1 to 20 are accepted ";
  36.                 cout << endl; //cout << "\n"
  37.                 return 0; //this will end the program if wrong input is given
  38.                 cout << endl;
  39.             }
  40.         }
  41.         return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement