// Torrez, Elaine CS1A Chapter 5 P. 298, #21
/******************************************************************************************
*
* Square Display
*
* --------------------------------------------------------------------------------
* This program asks the user for a number between 1 and 15 and then displays a
* square made of the letter 'X' with sides equal to that number.
* --------------------------------------------------------------------------------
*
* INPUT
* size : The size of the square (1–15)
*
* OUTPUT
* A square pattern made of the letter 'X'
*
*******************************************************************************************/
#include <iostream>
#include <limits>
using namespace std;
int main ()
{
int size; // INPUT - Size of the square
// Prompt user for input
cout << "Enter a number between 1 and 15: ";
while (!(cin >> size) || size < 1 || size > 15)
{
cout << "ERROR: Enter a number between 1 and 15: ";
cin.clear(); // clear error flag
cin.ignore(numeric_limits<streamsize>::max(), '\n'); // discard bad input
}
cout << endl;
// Display the square pattern
for (int row = 0; row < size; ++row)
{
for (int col = 0; col < size; ++col)
{
cout << "X";
}
cout << endl; // move to next line after each row
}
return 0;
}