Thread: House

  1. #1
    Registered User
    Join Date
    Feb 2013
    Posts
    2

    House

    In this code,the windows of the house are rectangular.Is there any modification that can be made to change them into diamond shapes.I tried a lot,but the windows came one below the other.

    Code:
    #include<stdio.h>
    void main() 
    {
        int i,j,k;
        for(i=1;i<=10;i++)
        {
            for(j=1;j<=10-i;j++)
            {
                printf(" ");
            }
            for(j=1;j<=i;j++)
            {
                          printf("=");
            }
            for(j=1;j<=50;j++)
            {
            if(((i>=3&&i<=8)&&(j>=3&&j<=8))||((i>=5&&i<=6)&&    (j>=9&&j<=18))||((i>=3&&i<=8)&&(j>=19&&j<=24))||((i>=3&&i<=4)&&(j>=27&&j<=48))||((i>=5&&i<=6)&&(j>=37&&j<=39))||((i>=7&&i<=8)&&(j>=27&&j<=48)))
    
    
                    printf(" ");
            else
                printf("=");
            }
            for(j=1;j<=i;j++)
            {
                printf("=");
            }
        printf("\n");
        }
    for(i=1;i<=25;i++)
    {
        for(j=1;j<=10;j++)
        {
                         printf(" ");
        }
            for(j=1;j<51;j++)
            {
    if(((i>=5&&i<=9)&&(j>=3&&j<=10))||((i>=5&&i<=9)&&(j>=41&&j<=48))||((i>=13&&i<25)&&(j>=20&&j<=31)))
                          printf(" ");
    else
        printf("=");
        }
            printf("\n");
        }
    }

  2. #2
    Registered User
    Join Date
    May 2012
    Posts
    1,066
    1) Indent your code. It looks awful!

    2) An easy solution would be to "draw" the house in a 2D-char array and just print the array line by line. If you are forced to use just nested for-loops, try to "draw" two diamonds next to each other and then integrate this part into your code.

    Bye, Andreas

  3. #3
    Registered User
    Join Date
    Feb 2013
    Posts
    2
    Thank You Very much.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sony back in the dog house
    By Salem in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 08-29-2007, 01:15 PM
  2. I hate Dr. House!
    By Mario F. in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 10-02-2006, 06:27 AM
  3. poker full house!!
    By noodle24 in forum C++ Programming
    Replies: 2
    Last Post: 05-19-2006, 09:09 PM
  4. Expendable house program, please help
    By ademkiv in forum C Programming
    Replies: 3
    Last Post: 02-21-2006, 06:49 AM
  5. Somewhat unusual house sale.
    By adrianxw in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 11-06-2005, 11:27 PM