# Nested Loop Structure Pyramid

Page 1 of 1

## 5 Replies - 15063 Views - Last Post: 14 April 2010 - 06:02 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=167983&amp;s=1a26d03db109fe137c1f5e24ee753835&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 roldown

Reputation: -3
• Posts: 24
• Joined: 14-April 10

# Nested Loop Structure Pyramid

Posted 14 April 2010 - 04:49 AM

Hello C++ users i need help for a question of my Assignment, as this website is my last resort. The Questions asks me to create a pyramid out of asterisks.
That looks likes this

******************
.****************
..**************
...************
....**********
.....********
......******
the Dots are spaces.

This Pyramid goes starts at 18 at the tops, and goes down by 2 each row.
I Can not figure out how to subtract 2 from each row going down. and how to leave spaces before the character symbols.
I have spent the last days in the library, reading past books trying to figure out and trying to find past examples, but no book seems to direct Nested Loop Structures to what the assignment wants.
This is my current Code that is getting me no where.
```#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int row, col,space;
row=0;
col=0;
space=2;

space=2;

for (row=1;row<=7;row++)
{
for(col=18;col>=1;col--)
cout<<"*";
cout<<endl;
}

system("pause");
return 0;
}
```

Any Help will be Appreciated

Is This A Good Question/Topic? 0

## Replies To: Nested Loop Structure Pyramid

### #2 Plus

• D.I.C Regular

Reputation: 41
• Posts: 414
• Joined: 24-November 08

## Re: Nested Loop Structure Pyramid

Posted 14 April 2010 - 05:00 AM

you simply at the first line print n stars,

each time stars are less, but gaps are more !

drop-down untill it is 1 star, then stop

```for (int i=0; i<8; i++)
{
for(int j=i; j>0; j--)
cout << " ";
for(int w=(8-i); w>0; w--)
cout << "*";
cout << endl;
}

```

### #3 roldown

Reputation: -3
• Posts: 24
• Joined: 14-April 10

## Re: Nested Loop Structure Pyramid

Posted 14 April 2010 - 05:18 AM

Im only Getting Half of the pyramid structure
```#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int i;
i=18;

for (int i=0; i<7; i++)
{
for(int j=i; j>0; j--)
cout << " ";
for(int w=(8-i); w>0; w--)
cout << "*";
cout << endl;
}

system("pause");
return 0;
}

```

and if i do make the second for value 18
it wont let me create spaces at the end.
if you know what i mean .. thanks for the reply by the way .

### #4 roldown

Reputation: -3
• Posts: 24
• Joined: 14-April 10

## Re: Nested Loop Structure Pyramid

Posted 14 April 2010 - 05:35 AM

I got it .. Thankyou sooooo much !

### #5 codeaholic

Reputation: 0
• Posts: 27
• Joined: 06-November 09

## Re: Nested Loop Structure Pyramid

Posted 14 April 2010 - 05:55 AM

plus is giving you a really good hint.
However you need to print 2 less stars each time therefore you need to change the second loop to :
```  for(int w=(8-(i*2)); w>=0; w--)
cout << "*";

```

I'm pretty sure this fixes the problem.
Note 8 should be replaced by the number of the rows of your pyramid

BTW don't forget to press the thank you Button if you think I helped.

### #6 codeaholic

Reputation: 0
• Posts: 27
• Joined: 06-November 09

## Re: Nested Loop Structure Pyramid

Posted 14 April 2010 - 06:02 AM

Oops I didn't see your last post.
Otherwise I wouldn't post my comment.
But I leave it in case it helps someone else in future.