Problem with using counter loop for forming empty rectangle

Hi, worlds worst programmer here for another question. I'm trying to use counter loops to form an empty rectangle as the title states above. The problem is, is that I just don't understand the logic behind using the while and if/else to form the printed "*" to actually do that stuff. Here is the source code below.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
  // Lab 2a, practical control structures
// Programmer:
// Editor(s) used: XP Notepad 
// Compiler(s) used: VC++ 2010 Express

#include <iostream>
using std::cin;
using std::cout;
using std::endl;

#include <string>
using std::string; 
using std::getline;

#include <cstdlib>




int main()

{
  // program number 2: practical control structures
  string buf;
  int squareSize;
  int verticalCounter=0;
  int horizontalCounter=0;
  

  cout << "Enter a number between 1-20 to determine the size of the rectangle: " << endl;
  cin >> buf; squareSize = atoi(buf.c_str());
  cin.ignore(1000,10);

  while (squareSize < 1 || squareSize > 20)
  {
  
	 if (squareSize==1)
	 {
		 cout << "*" <<endl;
	 }
	 else if (squareSize==2)
	  {
		 cout << "**" <<endl;
		 cout << "**" <<endl;
	  }
	while (squareSize > verticalCounter++)  
	
	{

   if( verticalCounter==1 ) 

{

while (squareSize > horizontalCounter++)

{   //draw firstline

cout<<"*";

}

} 

else if (verticalCounter == squareSize) 

{      //draw lastline

while (squareSize > horizontalCounter++ ) 

{

cout<<"*";

}

} 

else 

{

cout<<"*";

while (squareSize - 2 > horizontalCounter++) 

{

cout<<" "<<endl;

}

cout<<"*"<<endl;


}

}

}

		
			cout << "Press ENTER to continue..."<<endl;
		    cin.get();
}
  


Any help would be great. I'd love to have a tutor to help me out, but they usually charge me an arm and a mouse for that.
This type of problem is easiest if you create two functions.
One function to draw the top or bottom border.
A second function to draw the intervening rows (left and right border only).

You might want to consider making your minimum square size 2.
A square of size 1 would be just a single asterisk and would require a special check to draw just one border of length one.

Call the function to print the top row for length n.
Call the function to print the left and right borders n-2 times.
Call the function to print the bottom border for length n.
Topic archived. No new replies allowed.