Simple problem, cant seem to figure out

I'm trying to get the output. like a bowling pin formation
*****
***
*


but I'm getting
*****
***
*

In my code I enter in that the spaces should be increased by one each time, but it doesn't seem to work on the second line.

#include<iostream.h>
#include<iomanip.h>
main ()
{
int Loop;
int Space;
char Star='*';
int d=0;
for(Loop = 5; Loop >= 1; Loop--)
{
for(Space = 0; Space < Loop; Space++)
{
cout <<setw(d)<< Star;
}

{
cout << "\n";
}
Loop=Space-1;
d+=1;
}
system ("pause");
return 0;
}
Last edited on
first of all, use the [ code] [ /code]-tag, so your code is more readable when you post it.

next, look up setw again
http://www.cplusplus.com/reference/iostream/manipulators/setw/

if that doesnt help, start your loop with 10 and look at the result. i think you'll see why the way you use setw here is not right.
(btw setw(0) and setw(1) behave the same).

and just three advices, you dont need { } around the cout<<"\n";, you forgot an "int" in front of main
and i think you want to use Loop-- (in the for-loop) and Loop = Space-1 to decrease Loop by two every step?
Just use Loop-=2 in the for-loop. so you can save a line of code. ;-)
Last edited on
Topic archived. No new replies allowed.