KDT85

Untitled

Oct 15th, 2022
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main ()
  5. {
  6.     char brick = '#';
  7.     char space = ' ';
  8.     int size = 6;
  9.     int j =0;
  10.  
  11.  
  12.     do // this section makes sure the input is valid
  13.     {
  14.         cout << "Please enter size\n(enter an integer between 1 and 100)\n>>";
  15.         cin >> size;
  16.    
  17.     } while ( size < 1 || size > 100 || isalpha(size)); // only works up to 64, why?
  18.     //                                                    //also if you enter a char it goes crazy!
  19.     cout << "Please enter a character for the brick\n>>";
  20.     cin >> brick; // user decides what character to build the pattern out of
  21.    
  22.     for (int i = 0; i < size; i++) // the rows
  23.     {
  24.         for(j = 0; j < size; j++) // the column
  25.         {
  26.             if (i + j == size - 1 || i == 0 || j == 0) // the logic to decide what to print
  27.             {
  28.                 cout << brick;
  29.             }
  30.             else
  31.             {
  32.                 cout << space;
  33.             }
  34.         }
  35.         cout << endl;   // go to next row
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment