fork download
  1. // Marvyn De La Torre CS1A Chapter 5, P.298, #22
  2. /**************************************************************
  3.  * Display A Square
  4.  * This program asks the user for the size of a square and
  5.  * displays the square using X characters.
  6.  *
  7.  * Input:
  8.  * A positive integer no greater than 15 representing the
  9.  * length of each side of the square.
  10.  *
  11.  * Output:
  12.  * A square made of X characters.
  13.  **************************************************************/
  14.  
  15. #include <iostream>
  16. using namespace std;
  17.  
  18. int main()
  19. {
  20. int size;
  21.  
  22. cout << "Enter the size of the square (1-15): ";
  23. cin >> size;
  24.  
  25. while (size < 1 || size > 15)
  26. {
  27. cout << "Enter a number from 1 to 15: ";
  28. cin >> size;
  29. }
  30.  
  31. for (int row = 1; row <= size; row++)
  32. {
  33. for (int column = 1; column <= size; column++)
  34. {
  35. cout << "X";
  36. }
  37.  
  38. cout << endl;
  39. }
  40.  
  41. return 0;
  42. }
Success #stdin #stdout 0.01s 5316KB
stdin
5
stdout
Enter the size of the square (1-15): XXXXX
XXXXX
XXXXX
XXXXX
XXXXX