fork download
  1. //Dione Torrevillas CS1A Chapter 5, P. 298, #22
  2. //
  3. /**********************************************************************
  4.  *
  5.  * SQUARE DISPLAY
  6.  *
  7.  * This program asks the user for a positive integer no greater
  8.  * than 15. It then displays a square made of the character X.
  9.  * The number entered determines the length of each side.
  10.  *
  11.  * INPUT
  12.  * size : Length of each side of the square
  13.  *
  14.  * OUTPUT
  15.  * X characters : Square displayed on the screen
  16.  *
  17.  **********************************************************************/
  18.  
  19. #include <iostream>
  20. using namespace std;
  21.  
  22. int main()
  23. {
  24. int size; //INPUT - Size of the square
  25. int row; //CALC - Row counter
  26. int column; //CALC - Column counter
  27.  
  28. //
  29. // Get User Input
  30. //
  31. cout << "Enter a positive integer from 1 through 15: ";
  32. cin >> size;
  33.  
  34. //
  35. // Validate Input
  36. //
  37. while (size < 1 || size > 15)
  38. {
  39. cout << "Please enter a number from 1 through 15: ";
  40. cin >> size;
  41. }
  42.  
  43. //
  44. // Display Square
  45. //
  46. for (row = 1; row <= size; row++)
  47. {
  48. for (column = 1; column <= size; column++)
  49. {
  50. cout << "X";
  51. }
  52.  
  53. cout << endl;
  54. }
  55.  
  56. return 0;
  57. }
Success #stdin #stdout 0s 5316KB
stdin
5
stdout
Enter a positive integer from 1 through 15: XXXXX
XXXXX
XXXXX
XXXXX
XXXXX