Lost in my loops

Basically I'm trying to make a hollow triangle I'm almost done with it but I just cannot "close" it up.

My code spits this out-
-------*
------*-*
-----*---*
xxxxxx*-----*

Note the dashes are spaces in the program, I don't how to format on here.
Where the x's are supposed to be one level lower, covering the shape.
I don't know what to put before the setw line or where it's supposed to go.

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
#include "stdafx.h"
#include <iostream>
using namespace std;
#include <iomanip>
int main ()
{
	int x,y,z;
	cout << " Input height: " <<endl;
	cin >> y; //height
	
	for(x=1; x <= y; x++) //sets the pyramid height (rows)
	{
		
		for(z=y-x; z>=1; z--) //sets the appropriate spacing
			{
				cout << " ";
				
			}
			

		for(z=1; z<=x * 2 - 1; z++)   //prints out the number of stars based on the row
			{
				int a=x*2-1;
				
				if(z==1) //sets the left hand side
				{
				cout <<"*";
				}
				if(a==z)  //sets the right hand side
				{
				cout <<"*";
				}
				
				else //skips anything but the ends
				{
				cout << " ";
				}
				
			}
		
						
		
		
		cout << endl;
		if(y==x+1){cout << setfill ('x') << setw (y+x);}
	}
	
	system("PAUSE");
}
Topic archived. No new replies allowed.