Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Algorithms
  4. Console shapes?

Console shapes?

Scheduled Pinned Locked Moved Algorithms
csharphelptutorialquestioncode-review
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    venomation
    wrote on last edited by
    #1

    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

    L M 2 Replies Last reply
    0
    • V venomation

      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

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Total number of characters? Total number of stars? Total number of spaces? Half total number of spaces? Increment values? etc ...

      It's time for a new signature.

      1 Reply Last reply
      0
      • V venomation

        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

        M Offline
        M Offline
        MikeMarq
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups