Help with program to output a rectangle made of *'s

The code involves user input that determines the dimensions of the rectangle.
I have my code started, but I am also trying to make it where each row between the top and bottom consists of a star, then a " ", followed by another star --repeating.

How exactly do I accomplish this?

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
#include <iostream>
using namespace std;

int main()
{

int height;
int width;

cout << "Enter the height of the rectangle you want:  ";// Prompt for input
cin >> height; 			                    // Assign value for height of rectangle
cout << "Enter the width of the rectangle you want:   ";// Prompt for input
cin >> width;			                    // Assign value for width of rectangle

for (int column = 1; column <= width; column++)
	cout << '*';
cout << endl;
for (int row = 2; row <= height; row++)
{
	cout << '*';
	for (int column = 2; column < width; column++)
          cout << ' ';
	cout << '*' << endl;
}
for (int column = 1; column <= width; column++)
	cout << '*';
cout << endl;
}
Last edited on
So what is your problem?

Your program appears to work, although it puts out an extra row.
You need to exclude top and bottom row from the count.

Line 18 should be:
 
for (int row = 2; row < height; row++)

As I said, I'm wanting to have *s inside the box... Such as this:


*********
* * * * *
* * * * *
* * * * *
* * * * *
*********




And this is what I currently have with code posted above:


*********
*       *
*       *
*       *
*       *
*********


Topic archived. No new replies allowed.