Thread: Help progaming

  1. #1
    Registered User
    Join Date
    Sep 2010
    Posts
    9

    Help progaming

    I need help, i have to program that displays this output. Im kinda lost.



    This program will draw and compute the area of a fence that you specify.

    Please enter a width: 4
    Please enter a height: 3

    +----+
    | |
    | |
    | |
    +----+

    Area = 12 Perimeter = 14

    Would you like another fence? Y

    Please enter a width: 1
    Please enter a height: 1

    +-+
    | |
    +-+

    Area = 1 Perimeter = 4

    Would you like another fence? y

    Please enter a width: 2
    Please enter a height: 0

    +--+
    +--+
    Area = 0 Perimeter = 4

    Would you like another fence? Y

    Please enter a width: -2
    Negative numbers are not allowed!
    Please enter a width: 4
    Please enter a height: -3
    Negative numbers are not allowed!
    Please enter a height: 1

    +----+
    | |
    +----+

    Area = 4 Perimeter = 10

    Would you like another fence? N

    Thank you for using Fence-o-matic, GoodBye!


    the | are suppose to line up with the +
    Last edited by fri3dric3boi; 09-22-2010 at 12:43 PM.

  2. #2
    C lover
    Join Date
    Oct 2007
    Location
    Virginia
    Posts
    266
    You may want to post your code, inside of code tags.

  3. #3
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    What's your question?
    bit∙hub [bit-huhb] n. A source and destination for information.

  4. #4
    Registered User
    Join Date
    Sep 2010
    Posts
    9
    how do i display this output

  5. #5
    Registered User
    Join Date
    Sep 2010
    Posts
    9
    im new to this c programing stuff. :\

  6. #6
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    The fact that you are new to C programming does not, by any stretch of the imagination, mean that we are going to take pity on you and do your homework for you. You realize that, right?

  7. #7
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    428
    Did you try programming it yet? Posted code can help us fix an error. If you haven't even coded then you might want to start here.

    Cprogramming.com Tutorial: Introduction to C

    And keep moving through the lessons until you know enough to start coding. Then repost when you having a working example. Oh and before you post your code make sure you read:

    << !! Posting Code? Read this First !! >>

    Welcome to C ;o). Hope you enjoy it.

  8. #8
    Registered User
    Join Date
    Sep 2010
    Posts
    9
    Code:
    #include "stdafx.h"
    #include <stdio.h>
    #include <stdlib.h>
    #include <conio.h>
    
    int main (void)
    {
         int m;
    	 int n;
    	 int i;
    	 int j;
    	 int res1;
    	 int res2;
         printf("Please enter a width:");
         scanf("%i",&n);
         printf("Please enter a height:");
         scanf("%i",&m);
    
         for (j=0; j<m; j++)  
              printf("-");
         printf("\n");
         i=0;
         while (i<n)
         {
              printf("-");
              for (j=0; j<m-2; j++) 
                   printf("  ");
              printf("-\n");
              i++;
         }
         for (j=0;j<m;j++) 
              printf("-");
         printf("\n");
    	 res1=n*j;
    	 res2=n*2+j*2;
    	 printf("Area= %d Perimeter = %d\n",res1,res2);
    	 	system("pause");
    
    }

  9. #9
    Registered User
    Join Date
    Sep 2010
    Posts
    9
    im not sure how i put the + at the corners of the square. any help? and like when i try to do the | going down it double itself. what did i do wrong?

  10. #10
    Registered User
    Join Date
    Sep 2010
    Posts
    9
    i think i got the width and height switched

  11. #11
    Registered User
    Join Date
    Sep 2010
    Posts
    9
    Code:
    #include "stdafx.h"
    #include <stdio.h>
    #include <stdlib.h>
    #include <conio.h>
    
    int main (void)
    {
         int m;
    	 int n;
    	 int i;
    	 int j;
    	 int res1;
    	 int res2;
         printf("Please enter a width:");
         scanf("%i",&n);
         printf("Please enter a height:");
         scanf("%i",&m);
    	 printf("+");
         for (j=0; j<n; j++)  
             printf("-"); 
    		 printf("+");
         printf("\n");
         i=0;
         while (i<m)
         {
              printf("|");
              for (j=0; j<n-2; j++) 
                   printf("  ");
              printf("|\n");
              i++;
         }
    	 printf("+");
         for (j=0;j<n;j++) 
              printf("-");
    	 printf("+");
         printf("\n");
    	 res1=m*j;
    	 res2=m*2+j*2;
    	 printf("Area= %d Perimeter = %d\n",res1,res2);
    	 	system("pause");
    
    }
    ok i fixed it but its still doubling on the height
    its coming out like
    +----+
    | |
    | |

    | |
    | |

    | |
    | |
    +----+
    for width 4 and hieght 3.

  12. #12
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    >> not sure how i put the + at the corners of the square.
    Draw it with just one character first, like '-'. Then realize that one of the dimensions (length or height) on both sides has a '+' on the ends of the line. Thus you have corners.

  13. #13
    Registered User
    Join Date
    Sep 2010
    Posts
    9
    i got the plus "+" in the corners but like on the height the | doubles in two.
    so for height 3 it goes like this
    +
    |
    |

    |
    |

    |
    |
    +

  14. #14
    Third Eye Babkockdood's Avatar
    Join Date
    Apr 2010
    Posts
    352
    That doesn't look that hard to write. Have you even tried doing it yourself?

  15. #15
    Registered User
    Join Date
    Sep 2010
    Posts
    9
    i did do it my self. thats all i got so far....
    i need help the if else statements on how to put
    like if you put a negative number itll pop up saying
    "Negative numbers are not allowed!"
    and repeating the question again

Popular pages Recent additions subscribe to a feed