Making a frame with asterisks

I'm trying to modify a code I already have for a framed rectangle to make the user able to select how thick they want the border. This is an example of the desired output:

Welcome to Picture Maker!
Which shape should I draw? 3
Fill Character? *
Width? 8
Height? 5
Outline Width? 2

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


And currently my output is this:

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


I'm trying to understand how to modify the math in my existing code to make the frame. As always, help is very appreciated. Thank you.

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
#include <iostream>

using namespace std;

int main(){

  int width;
  int height;
  int shape;
  
  cout << "Welcome to Picture Maker!\nWhich shape should I draw?: ";
  
  cin >> shape;
  if(shape == 3){
    cout << "Width?: ";
    cin >> width;
    cout << "Height?: ";
    cin >> height;
    for(int a = 0; a < height; a++){
      for(int b = 0; b < width; b++){
      if(a == 0||a == height - 1||b == 0||b == width - 1){
        cout << "*";
      }else{
        cout << " ";
      }
      }
    cout << endl;
    }
  }
}
Last edited on
for some reason its not displaying the images properly on here

Use the output tags
[output]program output here[/output]
Last edited on
@Chervil thank you
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
using namespace std;
int main() {
	int width, height, border;
	cin >> width >> height >> border;
	char character;
	cin >> character;
	for (int i = 0; i < height; ++i) {
	    for (int j = 0; j < width; ++j) {
	        if (i < border || i >= height - border || j < border || j >= width - border)
		    cout << character;
		else
		    cout << ' ';
	    }
	    cout << '\n';
	}
}


Interesting site: http://wethecomputerguys.com/?s=pattern
Thank you!
Topic archived. No new replies allowed.