Please help me !!!!

This is a discussion on Please help me !!!! within the C++ Programming forums, part of the General Programming Boards category; I got an error message telling me that the local functions definitions are ilegal.. This si the Code... this function ...

  1. #1
    Registered User
    Join Date
    May 2003
    Posts
    2

    Please help me !!!!

    I got an error message telling me that the local functions definitions are ilegal.. This si the Code... this function is supposed to fill a graphic region on the screen.

    #include <iostream>
    using namespace std;

    const int TOP_ROW = 0;
    const int BOT_ROW = 199;
    const int LEFT_COL = 0;
    const int RIGHT_COL = 399;

    typedef int RowRange;
    typedef int ColRange;
    enum Color {black, blue, green, cyan, red, magenta, brown, white};
    typedef Color PixMatriz[BOT_ROW + 1] [RIGHT_COL + 1 ];

    void Fill(PixMatriz, RowRange, ColRange, Color);

    int main()
    {

    RowRange row = 5;
    ColRange col = 5;
    PixMatriz pixel;
    Color paintColor = black;

    Fill(pixel, row, col, paintColor);

    for( int i= 0; i< row; i++ )
    {
    for ( int j = 0; j< col; j++)
    {
    cout << pixel[row][col];
    }
    }
    void Fill(PixMatriz pixel, RowRange row, ColRange col, Color paintColor)
    {
    if ( pixel[row][col] == paintColor)
    return;

    pixel[row][col] = paintColor;

    if(row > TOP_ROW)
    Fill(pixel, row - 1, col, paintColor);

    if(col < RIGHT_COL)
    Fill(pixel, row, col + 1, paintColor);

    if(row < BOT_ROW)
    Fill(pixel, row + 1, col, paintColor);

    if(col > LEFT_COL)
    Fill(pixel, row, col - 1, paintColor);



    }

    return 0;
    }

    Please Help!!

  2. #2
    Registered User
    Join Date
    May 2003
    Posts
    43
    I can't help you with your problem, but you should put your code in code tags ( [ code ] and [ /code ] without spaces).

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    You have braces in the wrong place (curley brackets). If you lay your code out correctly, it's easy to spot these kind of mistakes
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  4. #4
    Just a Member ammar's Avatar
    Join Date
    Jun 2002
    Posts
    953
    Just define it outside the main function...
    Why do you want to define it inside the main function!?

    >>Derek5272
    It seems you like to be a mod!
    you are advising people to use code tags already!
    none...

  5. #5
    Registered User
    Join Date
    May 2003
    Posts
    43
    Originally posted by ammar
    >>Derek5272
    It seems you like to be a mod!
    you are advising people to use code tags already!
    Nah... I just like telling people what to do

  6. #6
    Registered User
    Join Date
    May 2003
    Posts
    2

    Better Code

    Code:
    #include <iostream>
    using namespace std;
    
    const int TOP_ROW = 0;
    const int BOT_ROW = 199;
    const int LEFT_COL = 0;
    const int RIGHT_COL = 399;
    
    typedef int RowRange;
    typedef int ColRange;
    enum Color {black, blue, green, cyan, red, magenta, brown, white};
    typedef Color PixMatriz[BOT_ROW + 1] [RIGHT_COL + 1 ];
    
    void Fill(PixMatriz, RowRange, ColRange, Color);
    RowRange row = 5;
    	ColRange col = 5;
    	PixMatriz pixel;
    	Color paintColor = black;
    int main()
    {
    	
    ;
    	
    	Fill(pixel, row, col, paintColor); 
    	
    	for( int i= 0; i< row; i++ )
    	{
    		for ( int j = 0; j< col; j++)
    		{
    		       cout << pixel[row][col];
    		}
    	}	
    	void Fill(PixMatriz pixel, RowRange row, ColRange col, Color paintColor)
    	{
    		
    		if ( pixel[row][col] == paintColor)
    			return;
    		
    		pixel[row][col] = paintColor;
    
    		if(row > TOP_ROW)
    			Fill(pixel, row - 1, col, paintColor);
    
    		if(col < RIGHT_COL)
    			Fill(pixel, row, col + 1, paintColor);
    		
    		if(row < BOT_ROW)
    			Fill(pixel, row + 1, col, paintColor);
    
    		if(col > LEFT_COL)
    			Fill(pixel, row, col - 1, paintColor);
    
    
    		
    	}
    
    	return 0;
    }
    Can Help?

  7. #7
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>Can Help?
    Help with doing what, exactly?
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  8. #8
    Registered User
    Join Date
    May 2003
    Posts
    43
    I'm assuming it is the same problem from his other thread...

    I got an error message telling me that the local functions definitions are ilegal.. This si the Code... this function is supposed to fill a graphic region on the screen.
    Programmer's Law:

    If your program doesn't work, look for the part that you didn't think was
    important.

  9. #9
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    try taking out the ; in main right before the Fill declaration.

  10. #10
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Threads merged.

    Your code structure should look more like this:
    Code:
    #include <iostream>
    using namespace std;
    
    // Global variables, typedefs etc go here
    
    
    // Function prototype:
    void Fill(PixMatriz pixel, RowRange row, ColRange col, Color paintColor);
    
    // Now into the main() function
    int main(void)
    {
      /*
       Some code here
       */
    }
    
    // And finally, the fill() function
    void Fill(PixMatriz pixel, RowRange row, ColRange col, Color paintColor)
    {
      /*
       Some code here
       */
    }
    See how the structure differs from yours?

    Like I said, your }'s are in the wrong place.
    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

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