Oct 15, 2014 at 4:27pm Oct 15, 2014 at 4:27pm UTC
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 Oct 15, 2014 at 4:27pm Oct 15, 2014 at 4:27pm UTC
Oct 15, 2014 at 4:32pm Oct 15, 2014 at 4:32pm UTC
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
Oct 15, 2014 at 4:38pm Oct 15, 2014 at 4:38pm UTC
I neet it to display the same triangle but inverted so three wuld look like this
*
**
***
**
*
Oct 15, 2014 at 4:39pm Oct 15, 2014 at 4:39pm UTC
could you explain set w not familiar
have heard of set precision same thing?
Oct 15, 2014 at 4:45pm Oct 15, 2014 at 4:45pm UTC
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
Oct 15, 2014 at 4:50pm Oct 15, 2014 at 4:50pm UTC
#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;
}
Oct 15, 2014 at 5:05pm Oct 15, 2014 at 5:05pm UTC
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;
}
Oct 15, 2014 at 5:06pm Oct 15, 2014 at 5:06pm UTC
so is something cancelling it out?
Oct 15, 2014 at 5:14pm Oct 15, 2014 at 5:14pm UTC
#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;
}
Oct 15, 2014 at 5:15pm Oct 15, 2014 at 5:15pm UTC
so I think im on the right path now but it geeks out when I compiler
Oct 15, 2014 at 5:17pm Oct 15, 2014 at 5:17pm UTC
#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;
}
Oct 15, 2014 at 5:18pm Oct 15, 2014 at 5:18pm UTC
got it exept ideally it would only have one row with five but progress!