fork download
  1. // Drew Duffey CSC5 Chapter 5, P.298, #22
  2. //
  3. /*******************************************************************************
  4.  *
  5.  * CREATE RECTANGLE
  6.  * _____________________________________________________________________________
  7.  * This program will generate a rectangle with specific dimensions, using the
  8.  * character 'X'.
  9.  * _____________________________________________________________________________
  10.  * INPUT
  11.  * Square X : How many columns the rectangle should be
  12.  * Square Y : How many rows the rectangle should be
  13.  *
  14.  * OUTPUT
  15.  * The output for this program is the rectangle drawn given the dimensions.
  16.  *
  17. *******************************************************************************/
  18. #include <iostream>
  19. #include <iomanip>
  20. using namespace std;
  21. int main ()
  22. {
  23. int count;//CALC - Counter for loops
  24. int count2;//CALC - Counter for loops
  25. int sqX;//INPUT - How many columns the rectangle should be
  26. int sqY;//INPUT - How many rows the rectangle should be
  27.  
  28. //Prompt input for dimensions
  29. cout << "Input the X and Y dimensions of a rectangle. "
  30. << "They should be no more than 15, and a space should seperate them."
  31. << endl;
  32. cin >> sqX >> sqY;
  33.  
  34. //Check to see if inputs are valid
  35. if (sqX > 15 || sqY > 15 || sqX < 1 || sqY < 1)
  36. {
  37. cout << "\nINVALID INPUT. TRY AGAIN.";
  38. return 0;
  39. }
  40.  
  41. //Draw rectangle
  42. cout << endl;
  43. for (count = 1; count <= sqY; count++)
  44. {
  45. for (count2 = 1; count2 <= sqX; count2++)
  46. {
  47. cout << "X";
  48. }
  49.  
  50. cout << endl;
  51. }
  52.  
  53. return 0;
  54. }
Success #stdin #stdout 0s 5316KB
stdin
4 4
stdout
Input the X  and Y dimensions of a rectangle. They should be no more than 15, and a space should seperate them.

XXXX
XXXX
XXXX
XXXX