draw pentagon with *

Is there a way to hard code a pentagon in the console with a loop? I've done it for a triangle so am trying to find a similar way to do it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
 	cout<<"  \tA"<<endl; 
	for (int i = 0; i < 10; i++){
		for (int k = 0; k < (10 - i); k++) {
			cout << " ";}
		for (int h = 0; h < (((i - 1) * 2) + 1); h++){
			cout << "*";}
		for (int k = 0; k < (10 - 1 - i); k++) {
			cout << " ";}
		cout << endl;}

	for (int i = 0; i < (((10 - 1) * 2) + 1); i++){
		cout << "*";}
	cout<<endl; 
		cout<<"  B\t\tC"<<endl; 
Try making pentagons of various sizes by hand to get an idea of what the code should be doing.
I would draw a triangle, and then draw half of an upside triangle with half the slope of the first triangle.
Topic archived. No new replies allowed.