# Help with christmas tree shape

Page 1 of 1

## 2 Replies - 9458 Views - Last Post: 11 December 2009 - 02:49 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=144686&amp;s=2b9dd9d0baa99c901cc79c0a1cd8251f&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 Upheaval

Reputation: 0
• Posts: 5
• Joined: 02-November 09

# Help with christmas tree shape

Posted 10 December 2009 - 07:34 AM

I'm writing a method to create an xmas tree with stars.

Allright so far i came up with this :

```static void DrawSquare(int x, int y)
{
for (int v = 0; v < x; v++)
{
for (int h = 1; h <= y; h++)
{
Console.Write("*");
}

Console.WriteLine();
}
}

static void DrawTree(int x)
{
for (int v = 0; v < x; v++)
{
for (int s = v + 1; s < x; s++)
{
Console.Write(" ");
}

for (int star = 2 * v; star >= 0; star--)
{
Console.Write("*");
}
Console.WriteLine();
}
}

```

Now the Square isn't in the middle of the tree.
I'm thinking about using a third parameter in the square method and using Console.SetCursorPosition().
I also came up with a possible formula :

Value of spaces from the 1st star of the triangle - (square width / 2)

But i'm not shure how to implement it in my code. Can anyone help me out here ?

Thx.

Is This A Good Question/Topic? 0

## Replies To: Help with christmas tree shape

• D.I.C Regular

Reputation: 118
• Posts: 388
• Joined: 14-June 09

## Re: Help with christmas tree shape

Posted 10 December 2009 - 03:46 PM

This should do the trick, it's not hard, just think carefully about each step the iteration needs to do. However it would be neater(I think) to make DrawTree make the call to DrawSquare in order to draw the stem of the tree, so you only need to make one call yourself. But I'll leave it up to you to implement that

```		static void DrawSquare(int x, int y, int offset)
{
for (int v = 0; v < x; v++)
{
for (int h = 1; h <= (y+offset); h++)
{
if (h <= offset)
{
Console.Write(" ");
}
else
{
Console.Write("*");
}
}

Console.WriteLine();
}
}
```

### #3 Upheaval

Reputation: 0
• Posts: 5
• Joined: 02-November 09

## Re: Help with christmas tree shape

Posted 11 December 2009 - 02:49 AM