Console shapes?
-
I need some help as I am finding it hard to create a program that can make character shapes such as a triangle in a console application (C#):
\* \*\*\* \*\*\*\*\* \*\*\*\*\*\*\*
As an example of what I would like to print, i.e. I want the triangle's height 4 and my program will draw a triangle as described. This is so that I can improve on control structures, squares and rectangles are easy :-D
-
I need some help as I am finding it hard to create a program that can make character shapes such as a triangle in a console application (C#):
\* \*\*\* \*\*\*\*\* \*\*\*\*\*\*\*
As an example of what I would like to print, i.e. I want the triangle's height 4 and my program will draw a triangle as described. This is so that I can improve on control structures, squares and rectangles are easy :-D
-
I need some help as I am finding it hard to create a program that can make character shapes such as a triangle in a console application (C#):
\* \*\*\* \*\*\*\*\* \*\*\*\*\*\*\*
As an example of what I would like to print, i.e. I want the triangle's height 4 and my program will draw a triangle as described. This is so that I can improve on control structures, squares and rectangles are easy :-D
Basically the way to approach this is to draw a rectangle like you did before but put some conditions in to determine if you should print a star or a blank. First to get the width: Notice that except for the top line the triangle's width increases by 2 for each line it goes down. Therefore: Width = (Height * 2) - 1 To determine whether to draw a star you need to find if you are close enough to the center of the triangle. Center = Width / 2 On each line the triangle gets one wider in each direction so you need 2 variables to hold the range where stars should be drawn. So if you use Min and Max as your variable the should initally be set to Center and then subtract 1 from min each line you go down and add 1 to max each line you go down. You can then use these variable to test if your loop counter is between these 2 variables. Hope this helps, Mike