Thread: for loops are confusing me

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    60

    Unhappy for loops are confusing me

    So i'm trying to print this flag still that is a rectangle with an x going from end to end using a W for white spaces and --- for the X since it always has to be the width of the X. here is what i have so far and i can't figure out what to do to ge the other half.
    Code:
    for(lineColor = 0; lineColor < flagSize; lineColor++){                                 
              for(lineColor2 = 0; lineColor2 < lineColor; lineColor2++){                           
                 printf("W");                                                                      
              }                                                                                    
              printf("---\n");                                                                     
            }

  2. #2
    Registered User
    Join Date
    Oct 2007
    Posts
    60
    and then the other thing is printing triangles sort. well I'm trying to have something like this
    ------GGGGGGGGGGGGGGGGG
    ----------------GGGGGGGGGGGG
    --------------------------GGGGGG
    -------------------------------------

    so far i have this
    Code:
    midPoint = (flagSize / 2) + 1;                                                          
           incrementSize = flagWidth / midPoint;                                                   
                                                                                                   
           for(lineCntr = 1; lineCntr < midPoint; lineCntr++){                                     
              for(centerColor = 0;centerColor < lineCntr; centerColor++){                          
                 printf("-");                                                                      
                 printf("G");                                                                      
              }                                                                                    
              printf("\n");                                                                        
           }
    Last edited by trprince; 11-01-2007 at 03:51 PM. Reason: added code

  3. #3
    Syncopated Kestrel andrew.bolster's Avatar
    Join Date
    Nov 2007
    Location
    Belfast
    Posts
    45
    what about something like
    Code:
    int width=10;
    	int height=10;
    	int i,j;
    	for(i=0;i<=height;i++)
    	{
    		for(j=0;j<=width;j++)
    		{
    			if((i==j)||((height-i)==(j))) printf("W");
    			else printf(" ");
    		}
    	printf("\n");
    	}

  4. #4
    Registered User
    Join Date
    Oct 2007
    Posts
    60
    ok thanks...noe this dag on triangle one

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. scanf is confusing me.
    By babelosopher in forum C Programming
    Replies: 10
    Last Post: 07-12-2007, 04:22 PM
  2. Most confusing language
    By Suchy in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 04-22-2007, 09:08 PM
  3. confusing error messages?
    By ssjnamek in forum C Programming
    Replies: 6
    Last Post: 01-26-2006, 08:56 PM
  4. Arrays are confusing...
    By GavinHawk in forum C Programming
    Replies: 10
    Last Post: 11-29-2005, 01:09 AM
  5. Confusing Pointer
    By loko in forum C Programming
    Replies: 4
    Last Post: 08-29-2005, 08:52 PM