1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Help with code (parse error)

Discussion in 'C++' started by BWIGLEY, Sep 30, 2006.

  1. BWIGLEY

    BWIGLEY New Member

    Joined:
    Sep 30, 2006
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Basically I've just started making a game. So far it makes an array 25 by 20 and tries to make five rooms within it.
    In scr_make_room() there's parse errors:
    20 C:\c\Rooms\Untitled1.c parse error before "top_x"
    28 C:\c\Rooms\Untitled1.c parse error before "first_square_x"
    35 C:\c\Rooms\Untitled1.c parse error before '}' token

    Why are these happening?
    Code:
    int room_square[25][20], selected = 1, squares = 1, first_square_x
    = -1, first_square_y = 1;
    
     void scr_make_room(void) //Make a room
        {
        int top_x, roomx, top_y, roomy, xplus, yplus;
    
        top_x = 8; //floor(random(21))+1 //Do this later when
        roomx = 5; //floor(random(8))+1  //I can use random()
        top_y = 12; //floor(random(16))+1 // and floor()
        roomy = 5; //floor(random(8))+1
    
        //Turn all the wall squares within the room to floor
        for (xplus = 0; xplus < roomx; xplus++)
            {
            for (yplus = 0; yplus < roomy; xplus++)
                {
    
                // make sure it's in the room
    20:         if top_x + xplus < 24 && top_y + yplus < 19 //***PARSE
    ERROR
                    {
                    if room_square[top_x+xplus][top_y+yplus] == 0 //if
    there is wall
                        {
                        room_square[top_x+xplus][top_y+yplus] = 1; //make
    it floor
                        squares+=1; //increase the number of squares made
    
                        //record the first square made(ever)
    28:                 if first_square_x == -1 //***PARSE ERROR
                            {
                            first_square_x = top_x+xplus;
                            first_square_y = top_y+yplus;
                            }//endi
                        }//endi wall
                    }//endi in room
    35:          }//end for y //***PARSE ERROR
            }//end for x
        }//end scr_make_room()
    
    int main()
        {
    int i, j;
    
    for (i = 0; i < 25; i++)
        {
        for (j = 0; j < 20; i++)
            {
            room_square[i][j]=0;
            }
        }
    
    for (i=0; i<5; i+=1)  //make 5 rooms
    {
    scr_make_room();
    
    }
    
    return 0;
        } 
     
  2. Bill Pursell

    Bill Pursell New Member

    Joined:
    Nov 29, 2006
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    The syntax "if x" is invalid. You must
    use parentheses, eg "if(x)"
     

Share This Page