fork download
  1. //Brandon West CSC5 Chapter 5, p. 298,#22
  2. /*************************************************************************
  3.  *
  4.  * SQUARE DISPLAY OUTPUT
  5.  * _______________________________________________________________________
  6.  * This program asks user to enter positive integer no greater than 15,
  7.  * then displays a square on the screen using character 'X'. The number
  8.  * entered by user is the length of each side of the square.
  9.  * _______________________________________________________________________
  10.  *INPUT
  11.  * sideLength : Store user side length input
  12.  *
  13.  *OUTPUT
  14.  * row : Track number of rows
  15.  * col : Tracks number of columns
  16.  *
  17.  ************************************************************************/
  18. #include <iostream>
  19. using namespace std;
  20.  
  21. int main(){
  22.  
  23. int sideLength; //User input side length
  24. int row; //Counter for output rows
  25. int col; //Counter for output columns
  26.  
  27. //Get side length
  28. cout << "\nEnter positive number no greater than 15: \n";
  29. cin >> sideLength;
  30.  
  31. //Validate side length is 1 - 15
  32. while (sideLength < 1 || sideLength > 15){
  33. cout << "\nEnter positive number between 1 - 15: \n";
  34. cin >> sideLength;
  35. }
  36. if (sideLength >= 1 && sideLength <= 15){
  37.  
  38. //Built row
  39. for (row = 1; row <= sideLength; row++)
  40. {
  41. //Build column
  42. for (col = 1; col <= sideLength; col++){
  43.  
  44. cout << "X";
  45. }
  46. cout << endl;
  47. }
  48. }
  49.  
  50. return 0;
  51. }
  52.  
Success #stdin #stdout 0s 15224KB
stdin
16
-1
5
stdout
Enter positive number no greater than 15: 

Enter positive number between 1 - 15: 

Enter positive number between 1 - 15: 
XXXXX
XXXXX
XXXXX
XXXXX
XXXXX