need help with this function, please help !

This is a discussion on need help with this function, please help ! within the C Programming forums, part of the General Programming Boards category; i still very newbie, and i was working on this simple project. basically we have to display a checkerboard pattern ...

  1. #1
    Registered User
    Join Date
    Sep 2008
    Location
    Jakarta
    Posts
    18

    need help with this function, please help !

    i still very newbie, and i was working on this simple project. basically we have to display a checkerboard pattern like this :

    Code:
     *  *  *  *  *  *  *  *
       *  *  *  *  *  *  *  *
     *  *  *  *  *  *  *  *
       *  *  *  *  *  *  *  *
     *  *  *  *  *  *  *  *
       *  *  *  *  *  *  *  *
     *  *  *  *  *  *  *  *
       *  *  *  *  *  *  *  *
    with only using these tree output statements once :

    Code:
    printf ( "* " );
    printf ( " " );
    printf ( "\n" );
    this is my progress this far, can anyone tell me what is my mistake ?

    Code:
    #include <stdio.h>
    
    main ()
    {
    
    	int row = 1; // declare the interger
    	int column; // declare the 2nd interger
    	
    	while ( row <= 8 ) { // open curly bracket for the 1st 'while'
    		 
    			column = 1; // declare the value of interger
    			
    		while ( column <= 8 ) { // open curly bracket for the 2nd 'while'
    		
    			printf ( "* " ); 
    			column++;
    			
    			if ( row &#37; 2 == 0 && column == 2 ) { // open curly bracket for 'if'
    			
    				printf ( " " );
    				
    				} // close bracket for 'if'
    		}// close bracket for inner 'while'
    		
    		
    		
    		row++ ;
    		printf( "\n" );
    		
    	} // close bracket for outer 'while'
    	
    	
    	return 0;
    
    }
    that's all ! thx !

  2. #2
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    1. use for loops where it makes sense (it does here)
    2. You should print a space at the start of every even row

    For example:
    Code:
       for(row = 1; row <= 8; row++)
       {
          if(row &#37; 2 == 0)
             printf(" ");
    
          for(col = 1; col <= 8; col++)
          {
             printf(" *");
          }
    
          printf("\n");
       }

  3. #3
    Registered User
    Join Date
    Sep 2008
    Location
    Jakarta
    Posts
    18
    wow ! thx mate ! never thought of that...

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,988
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    UnknownAmateur Programmer
    Join Date
    Sep 2008
    Location
    Were definitly not in Kasas anymore...
    Posts
    25

    Lightbulb Check

    To do that I would simply type:

    Code:
    main()
    {
        int repeat;
      
        for(repeat=0;repeat<4;repeat++)
        {
             printf("* * * * * * * *\n * * * * * * * *\n");
        }
    }
    I tried it and it worked

    -C-Compiler

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Except the original post says:
    with only using these tree output statements once :

    Code:

    printf ( "* " );
    printf ( " " );
    printf ( "\n" );
    So using longer printf's isn't following the specification.
    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 04:06 PM
  3. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 02:01 AM
  4. Replies: 28
    Last Post: 07-17-2006, 12:35 AM
  5. const at the end of a sub routine?
    By Kleid-0 in forum C++ Programming
    Replies: 14
    Last Post: 10-23-2005, 07:44 PM

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