Thread: What is the logic?

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    2

    What is the logic?

    http://img828.imageshack.us/img828/5028/projecta.jpg

    I have a project something like in this picture. Printing a house to screen. If you look at the pic you understand what i mean. Printing vertical and horizontal ractangle is ok but i couldn't manage to do the roof. Actually i couldn't set up a logic in my mind. How should i set a "for" loop. While the spaces decrease the "/" should increase. (Door and windows are not important) How should i do that. Thanks...

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    The roof is just a pyramid of char's. On the left side of the pyramid, you'll print a '/', and in the middle column, you'll print a '+', and on the right side, you'll print a '\'.

    Don't over-complicate it.

  3. #3
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    I just made this quickly, but it might work:
    Code:
    #include <stdio.h>
    
    #define HOUSE_WIDTH  35
    #define HOUSE_HEIGHT ((HOUSE_WIDTH) / 2)
    #define ROOF_HEIGHT  (((HOUSE_HEIGHT) / 2) + 1)
    
    int main(void)
    {
      int row;
      int i;
    
      for(row = 0;row <= ROOF_HEIGHT;++row)
      {
        int shingles = (double)HOUSE_WIDTH / ROOF_HEIGHT * row / 2;
        for(i = 0;i < HOUSE_WIDTH / 2;++i)
          putchar(((HOUSE_WIDTH / 2) - i) > shingles ? ' ' : '/');
        putchar('+');
        for(i = 0;i < HOUSE_WIDTH / 2;++i)
          putchar(i >= shingles ? ' ' : '\\');
        putchar('\n');
      }
    
      return 0;
    }
    My output:
    Code:
                     +
                    /+\
                  ///+\\\
                /////+\\\\\
              ///////+\\\\\\\
            /////////+\\\\\\\\\
          ///////////+\\\\\\\\\\\
        /////////////+\\\\\\\\\\\\\
      ///////////////+\\\\\\\\\\\\\\\
    /////////////////+\\\\\\\\\\\\\\\\\
    If you understand what you're doing, you're not learning anything.

  4. #4
    Registered User
    Join Date
    Oct 2010
    Posts
    2
    Yea it really works. Thanks...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Handling logic and draw cycles
    By DavidP in forum Game Programming
    Replies: 1
    Last Post: 07-25-2009, 10:15 AM
  2. Digital Logic
    By strokebow in forum Tech Board
    Replies: 3
    Last Post: 12-09-2006, 01:05 PM
  3. Circular Logic
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 10-15-2001, 08:10 PM