How to make a rectangle using loops

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • samreen gull
    New Member
    • Jul 2010
    • 1

    How to make a rectangle using loops

    hi
    i want make a rectangle in loop condition.how i can make a 4 side border on screen tu showing stars?

    thaks you.
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    To draw a rectangle of asterisks you need to think like a computer. That is, think in terms of lines and not rectangles.

    These lines:

    *************** *
    *.............. ..............*

    are all you need to display a rectangle. Just display them as many times as needed and in the right order.

    The dots are spaces.

    Comment

    • whodgson
      Contributor
      • Jan 2007
      • 542

      #3
      Also I think you need two (for) loops .....one to control the rows and the second to control the columns in which the character or white space is printed.

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        Actually, you could just cout each line of the rectangle and use no loops at all.

        Comment

        • whodgson
          Contributor
          • Jan 2007
          • 542

          #5
          Yeeees-----but but would it be possible to react to user input specifying length and breadth using this coding method?
          i.e.
          Code:
          std::cout<<ch<<" "<<" "<<" "<<" "<<" "<<ch;

          Comment

          • weaknessforcats
            Recognized Expert Expert
            • Mar 2007
            • 9214

            #6
            Reacting to user input will require more code. I made the statement to liuiustrate that a rectangle does not need a loop to create it. Creating a flexible one whose size is not known until run time will require calculations and probably a loop.

            Comment

            Working...