Thread: Help making a hollow rectangle with thickness border

  1. #16
    Registered User
    Join Date
    Jun 2010
    Posts
    9
    Quote Originally Posted by Adak View Post
    Oh that must be a lie - noobs tell us "it doesn't work", all the time!!
    Using the logic formula produced the second piece of code I posted there and it does not produce boxes.

  2. #17
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    So where are you printing the spaces?
    Code:
    for each row
        for each column
            if row < thickness, print a wall
            if row > box size - thickness, print a wall
            if col < thickness, print a wall
            if col > box size - thickness, print a wall
            otherwise, print a space
        print newline
    Quzah.
    Hope is the first step on the road to disappointment.

  3. #18
    Registered User
    Join Date
    Jun 2010
    Posts
    9
    Quote Originally Posted by quzah View Post
    So where are you printing the spaces?
    Code:
    for each row
        for each column
            if row < thickness, print a wall
            if row > box size - thickness, print a wall
            if col < thickness, print a wall
            if col > box size - thickness, print a wall
            otherwise, print a space
        print newline
    Quzah.
    Does my else function not make sense where it is then?

  4. #19
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I'm going to give a tip.
    Let's start simple. Let width = 10, height = 10, thickness = 2.
    Now let the console be a coordinate system with origin in the upper-left corner.
    Let's see if you can follow me here.
    Row zero. We print stars all the way.
    Row one. We print stars all the way.
    Row two. We print two stars, 6 spaces, then 2 stars. Right?
    Repeat this for row 3-7.
    Now repeat row 0-1 and we're done.

    Let's try to generalize it.
    If row is 0 or 1 OR row > is 8 or 9, always print a star for every column.
    If row 2...7 AND column is 0 or 1 or 8 or 9, print a star.
    Else, print a space.

    Try implementing that first and the generalizing it to given values.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #20
    Registered User
    Join Date
    Jun 2010
    Posts
    2
    Elysia i would like to thank you. your logic helped a lot kinda feel bad that it took me this long to see it and how easy it seems now that i finally got it.
    this is what i got

    Code:
    for(row = 0; row < height; row++)
            {
            for(column = 0; column < width; column++)
            {
                  
                if(row < thickness)
                    {
                        printf("*");   //prints top part
                    }    
                if(row >= (height - thickness)) 
                    {       
                        printf("*");   // prints bottom part
                    }
                if(row >= thickness && row < (height - thickness) && column < thickness)
                    {
                        printf("*");
                    }
                if(row >= thickness && row < (height - thickness) && column > thickness && column <=(width - thickness))
                    {
                        printf(" ");
                    }     
                if(row >= thickness && row < (height - thickness) && column >=(width - thickness))
                    {
                        printf("*");
                    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling GNU MP
    By mattnp12 in forum C Programming
    Replies: 3
    Last Post: 06-23-2011, 03:58 PM
  2. GUI structure in C
    By officedog in forum C Programming
    Replies: 36
    Last Post: 11-19-2008, 02:33 PM
  3. Making Rectangle List Non-Overlapping
    By SMurf in forum Game Programming
    Replies: 2
    Last Post: 05-06-2006, 01:23 PM
  4. hollow rectangle
    By Unregistered in forum C Programming
    Replies: 7
    Last Post: 04-07-2002, 07:03 AM
  5. more with my 1st structure program
    By sballew in forum C Programming
    Replies: 42
    Last Post: 10-22-2001, 08:03 PM