need *FAST* HELP

May have waited to long to ask for help but here goes nothing my program is suppose to display a * triangle where you enter in the middle and it get smaller by one in either direction. My problem is my bottom is not displaying any idea where I went wrong

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
 #include<iostream> 
using namespace std; 
int main()
{ int TS; //TriangleSize
cout<<"enter Triangle size"<<endl; 
cin >> TS; 


 for (int x=1; x<=TS; x++) 
 { 
 for (int y=0; y<x; y++) 
 { 
 cout << "*"; 
 } 
 cout << endl; 
 } 
 for (int x=1; x>=TS; x--)
 {
     for(int y=0; y>x; y--)
 {
          cout<<"*";
 }
 cout<<endl;
 }
    system("Pause");
    return 0;
} 
Last edited on
What do you mean your bottom isn't showing? This is what I get when I put in TS size of 5


1
2
3
4
5
6
7
enter Triangle size
5
*
**
***
****
*****
use setw() to put the top point in the middle and output the rest of the stars for both sides using setw() -1... the base's setw() should end up to be 0
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
#include <iostream> 
#include <iomanip>
using namespace std;
int main()
{
	int TS; //TriangleSize
	int w;
	cout << "enter Triangle size" << endl;
	cin >> TS;
	w = TS;


	for (int x = 1; x <= TS; x++, w--)
	{
		cout << setw(w);
		for (int y = 0; y<x; y++)
		{
			cout << "*";
			if (y > 0)
				cout << "*";
		}
		cout << endl;
	}
	for (int x = 1; x >= TS; x--)
	{
		for (int y = 0; y>x; y--)
		{
			cout << "*";
		}
		cout << endl;
	}
	system("Pause");
	return 0;
}
I neet it to display the same triangle but inverted so three wuld look like this
*
**
***
**
*
could you explain set w not familiar
have heard of set precision same thing?
setprecision deals with floating point output...
setw() just pushes the output '*' how ever many times down the line you say
so if i say cout << setw(50) << "*';
the star would appear after 50 spaces
#include<iostream>
using namespace std;
int main()
{ int TS,x,y,w,v,ts; //TriangleSize
cout<<"enter Triangle size"<<endl;
cin >> TS,ts;

for (int x=1; x<=TS; x++)
{
for (int y=0; y<x; y++)
{
cout << "*";
}
cout << endl;
}

for (int w=1; w>=ts; w--)
{
for(int v=0; v>w; v--)
{
cout<<"*";
}
cout<<endl;
}
system("Pause");
return 0;
}
Think of your output as two separate triangles. In the example you showed, three should look like this:
*
**
***
**
*

It looks like you know how to print a triangle like this:
*
**
***

Can you print one after it that looks like this?
**
*
yes that's what I was trying to do I thought this would produce with additional triangle obviously im wrong because when I enter it into compiler it shows nothing

(int w=1; w>=ts; w--)
{
for(int v=0; v>w; v--)
{
cout<<"*";
}
cout<<endl;
}
so is something cancelling it out?
#include<iostream>
using namespace std;
int main()
{ int TS,x,y,w,v,ts; //TriangleSize
cout<<"enter Triangle size"<<endl;
cin >> TS,ts;

for (int x=1; x<=TS; x++)
{
for (int y=0; y<x; y++)
{
cout << "*";
}
cout << endl;
}

for (int w=ts; w>=1;--w)
{
for(int v=1; v<w; ++v)
{
cout<<"*";
}
cout<<endl;
}
system("Pause");
return 0;
}

so I think im on the right path now but it geeks out when I compiler
#include<iostream>
using namespace std;
int main()
{ int TS,x,y; //TriangleSize
cout<<"enter Triangle size"<<endl;
cin >> TS;

for (int x=1; x<=TS; x++)
{
for (int y=0; y<x; y++)
{
cout << "*";
}
cout << endl;
}

for (int x=TS; x>=1;--x)
{
for(int y=1; y<=x; ++y)
{
cout<<"*";
}
cout<<endl;
}
system("Pause");
return 0;
}
got it exept ideally it would only have one row with five but progress!
Topic archived. No new replies allowed.