aterisk squares!!! need help!

This is a discussion on aterisk squares!!! need help! within the C Programming forums, part of the General Programming Boards category; I had created this code, and a lot is missing from it, the input value is "h=6" and "v=4" it's ...

  1. #1
    Registered User
    Join Date
    Jan 2007
    Posts
    5

    Question asterisk squares!!! need help!

    I had created this code, and a lot is missing from it, the input value is "h=6" and "v=4"
    it's output is:
    *
    *
    *
    *******
    Code:
    #include <stdio.h>
    #include <conio.h>
    main()
    { int h,h1,v,v1;
      printf("Enter horizontal value:\n");
      scanf("%d",&h);
      printf("Enter vertical value:\n");
      scanf("%d",&v);
      h1=0;
      v1=0;
      while(v1<=v) {
      printf("\n*");
      v1++;
         while(h1<=h) {
            printf("*");
            h1++;
            }
       }
    getch();
    }

    the output supposed to be is an a square box of asterisk with an a 6X4 field. It should look like this:
    without the dashes
    ******
    *-----*
    *-----*
    ******
    Can anyone point me to the right direction here!!!
    I'm still new to c programming, barely a month ago.
    Anyone can give me a clue on this! Little and big help will be graciously accepted.
    thnx anyone in advance!
    Last edited by neosnk35; 01-11-2007 at 07:57 AM.

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,794
    Code:
    for( v1 = 0; v1 < v; ++v1 )
    {
        for( h1 = 0; h1 < h; ++h1 )
        {
            if( "This is a location in the middle of the rectangle" )
                putchar(' ');
            else
                putchar('*');
        }
        putchar('\n');
    }
    All you need to do is figure out how to determine if you are somewhere in the middle of the rectangle based on the h1 and v1 values. Shouldn't be to difficult to put in some tests of the values. A couple tests on each of the h1 and v1 values and'ed all together should suffice.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Registered User
    Join Date
    Jan 2007
    Posts
    5
    hk_mp5kpdwc thanx for some help! but the program needs more than that!
    I was told use the looping method! it is suppose work like this. the program ask for an input of two values, for testing i had used h=6 and v=4, it should generate an a squre box of asterisk with six horizontal asterisk on top,4 vertical asterisk on left corner and right corner to bottom, and six asterisk in the bottom! you still can use other values like 8x5,14x4 asterisk and it should generate an 8x5,14x4 square asterisk, anyways thanx again!

  4. #4
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,794
    ?????

    Those are loops... for loops. I just included the looping part which you could drop into the existing code you already have that asks the user for the two values (h and v). That code will work (if you figure out the missing part) for any values of h and v that the user enters.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  5. #5
    Registered User
    Join Date
    Jan 2007
    Posts
    5
    ok, i give up, can you pls tell me the missing part or give me an a example! This things are too new for me to see! plsss! thnx!

  6. #6
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,794
    Code:
    #include <stdio.h>
    #include <conio.h>
    int main()
    {
        int h,h1,v,v1;
        printf("Enter horizontal value:\n");
        scanf("%d",&h);
        printf("Enter vertical value:\n");
        scanf("%d",&v);
        for( v1 = 0; v1 < v; ++v1 )
        {
            for( h1 = 0; h1 < h; ++h1 )
            {
                if( h1 > 0 && h1 < h-1 && "figure out the vertical test portion" )
                    putchar(' ');
                else
                    putchar('*');
            }
            putchar('\n');
        }
        getch();
        return 0;
    }
    Blue is my code plopped directly into yours, replacing the while loops. Red is a portion of the "missing" part, I'm still going to try and get you to figure out the vertical portion of the tests; here's a hint, it is very similar to the horizontal portion already in place. Green is just a couple additions.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  7. #7
    Registered User
    Join Date
    Jan 2007
    Posts
    5
    thanx a lot friend! ill try my best to figure out the red part!
    thanks again!

  8. #8
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by neosnk35
    hk_mp5kpdwc thanx for some help! but the program needs more than that!



    I was told use the looping method!
    Oh, my sides are aching! Thanks for that!!


    Adak

  9. #9
    Registered User
    Join Date
    Jan 2007
    Posts
    5
    thanx!!hk_mp5kpdw, I had figured it out just recently, thanx for the big help!!

    [code]
    by the can anyone help to use gotoxy+loop, with that same problem

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Generating an image of squares?
    By vopo in forum C# Programming
    Replies: 3
    Last Post: 10-21-2008, 10:15 AM
  2. Forced moves trouble!!
    By Zishaan in forum Game Programming
    Replies: 0
    Last Post: 03-27-2007, 06:57 PM
  3. pass error before char
    By bazzano in forum C Programming
    Replies: 3
    Last Post: 03-26-2006, 11:00 AM
  4. Magic Squares!
    By ZAM777 in forum C++ Programming
    Replies: 1
    Last Post: 04-28-2004, 03:34 PM
  5. perfect squares?
    By ahalya in forum C++ Programming
    Replies: 2
    Last Post: 10-14-2001, 09:38 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21