Rectangle with "*", but inside it has to remain empty

Hi,
I have a code that makes a rectangle with "*" when I cin 2 numbers for width and Height, like this:
******
******
******
******

But now i have to make a rectangle that is empty inside.


Can anyone explain it to me?
Here is my code:
#include <iostream>
using namespace std;
int main(int argc, char **argv) {



int Height, Width;
cin >> Height;
cin >> Width;





for (int i = 0; i< Width; i++) {


for(int j = 0; j < Height; j++)
{
cout << "*";

}
cout << endl;

}
}
Last edited on
closed account (28poGNh0)
Maybe you look for this one

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, width;
    cin >> height;
    cin >> width;

    for (int i = 0; i< width; i++)
    {
        for(int j = 0; j < height; j++)
            cout << " ";
        cout << endl;
    }

    // Or with border
    for (int i = 0; i< width; i++)
    {
        for(int j = 0; j < height; j++)
        {
            if(i==0||j==0||i==width-1||j==height-1)
                cout << "*";
            else cout << " ";
        }
        cout << endl;
    }
}
Thank you, that's it. You are a lifesaver! :)
Topic archived. No new replies allowed.