Thread: Help fixing for loop

  1. #1
    Registered User
    Join Date
    Mar 2013
    Posts
    16

    Help fixing for loop

    Hi,

    I am just learning C, so I am sorry if my questions are trivial. I'm basically programming the "15-puzzle" which looks like this: File:15-puzzle.svg - Wikipedia, the free encyclopedia

    So I'm basically writing a function init_tiles() which initializes all 16 tiles to have a color and number, and then calls initialize_tile. I know that my steps are correct, but my for loop is incorrect. The board itself is comprised of 4 rows and 4 columns, so it's length is 16. Below is my code..if someone could help me fix my for loop, I'd appreciate it greatly! I basically have to loop through each tile in my global array title_data[16][21*21] which is basically a global 2 dimensional array that holds the colors for all the pixels for all of the tiles. Row = tile #, column = pixel color.

    Code:
     void init_tiles(){
    	int col, row;
    	int color;
    	int tile_index, digit1, digit2;
    
    
    	for(int col = 0; col < col.length; ++col) {
    		for (int row = 0; row < row.length; ++row) {
    			// calculate the background color for each tile
    			if (((col + row) / 2) == 0) {
    				color = WHITE;
    			}
    			else {
    				color = RED;
    			}
    			// calculate the 2 digits placed on each tile
    			tile_index = col + row * 4;
    			digit1 = (title_index + 1) / 10;
    			digit2 = (title_index + 1) % 10;
    
    
    			initialize_tile(tile_index, digit1, digit2, color, BLACK);
    
    
    
    
    		}
    	}
    
    
    	// for the blank tile, set all of the pixels to BLACK
    	// **TO DO: FOR each pixel in the tile,
    	//       tile_data[15][pixel] = BLACK;
    	for () {
    		tile_data[15][pixel];
    	}
    }

  2. #2
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Code:
    int col;
    ...
    col.length
    You might want to learn basic C before you start tackling relatively difficult problems.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Fixing Redundancy
    By Thorax in forum C Programming
    Replies: 2
    Last Post: 11-01-2011, 11:42 AM
  2. Need help with fixing modules
    By 116soulja in forum C Programming
    Replies: 10
    Last Post: 01-16-2010, 12:26 AM
  3. I need help fixing a warning
    By Nterpol in forum C Programming
    Replies: 13
    Last Post: 04-14-2006, 02:40 AM
  4. How would I got about fixing this?
    By SlyMaelstrom in forum C++ Programming
    Replies: 1
    Last Post: 04-23-2005, 05:34 AM
  5. Problem fixing this pc
    By Waldo2k2 in forum Tech Board
    Replies: 7
    Last Post: 05-23-2003, 12:59 PM

Tags for this Thread