ahhhhh a lil more help

This is a discussion on ahhhhh a lil more help within the C Programming forums, part of the General Programming Boards category; ok here's what i need when variables are base1=4 and height1=6: Code: * ** *** **** **** **** *** ** ...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    40

    ahhhhh a lil more help

    ok here's what i need when variables are base1=4 and height1=6:

    Code:
    *
    **
    ***
    ****
     ****
      ****
       ***
        **
         *
    here's the code i have:

    Code:
    for (row = 0; row < base1/2+2; row++)
    				{
    					for (col = 0; col<=row; col++)
    						if(col<height1)
    						printf("*");
    					printf("\n");					
    				}
    			for(row = base1; row>0; row--)
    				{
    					for (space = height1/2+1; space > row; space--)
    						printf(" ");
    					for(col = 1; col<=row; col++)
    					    printf("*");
    					printf("\n");
    				}

    and here's what i get:

    Code:
    *
    **
    ***
    ****
      ****
       ***
        **
         *
    i've been messing with this code for hours, if anyone can point me in the right direction then it would be sooooo helpful thanks!

  2. #2
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Code:
    	for( row = 0; row < height1 + base1 - 1; row++ ) {
    
    		for( col = 0; col < height1; col++ ) {
    
    			if( col > row ) break;
    
    			if( row >= base1 && col <= row - base1 ) printf( " " );
    			else printf( "*" );
    
    		}
    
    		printf( "\n" );
    
    	}
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  3. #3
    Registered User
    Join Date
    Oct 2002
    Posts
    40
    i can't use break;

  4. #4
    Registered User
    Join Date
    Oct 2002
    Posts
    40
    just curious how about this:

    Code:
       *
      **
     ***
    ****
    ***
    **
    *

  5. #5
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Originally posted by blindleaf
    i can't use break;
    Then I'm sure you can change the "if" statement around a little to make the program bypass the printing section when col > row. This will mimic the use of break by simply completing the for loop with the last few iterations doing nothing. Or, why not add a second test in the "for" statement itself.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A Lil Help With Inheritance...
    By frassunit in forum C++ Programming
    Replies: 16
    Last Post: 03-04-2009, 03:54 AM
  2. lil prob
    By psycho88 in forum C Programming
    Replies: 7
    Last Post: 12-01-2005, 12:04 PM
  3. annoying lil bug
    By baka1337 in forum C++ Programming
    Replies: 6
    Last Post: 04-23-2003, 01:36 AM
  4. i need a lil venting.
    By RoD in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 01-03-2003, 10:21 PM
  5. sorry i had to post it again (Need a lil help)
    By datainjector in forum C Programming
    Replies: 1
    Last Post: 06-27-2002, 08:52 PM

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