Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2011
    Location
    Romania, Bucharest
    Posts
    5

    Compilling error from lesson: 3DBuzz - C++ - Issue 3 - 7 Level (Using VC 2010)

    I am having a hard time with this errors:

    Error 1 error C2065: 'y' : undeclared identifier d:\diverse\lucru\visual studio 2010\projects\evilmonkeys\evilmonkeys\level.cpp 42 1 evilMonkeys
    Error 2 error C2065: 'y' : undeclared identifier d:\diverse\lucru\visual studio 2010\projects\evilmonkeys\evilmonkeys\level.cpp 42 1 evilMonkeys
    Error 3 error C2065: 'y' : undeclared identifier d:\diverse\lucru\visual studio 2010\projects\evilmonkeys\evilmonkeys\level.cpp 44 1 evilMonkeys
    Error 4 error C2065: 'y' : undeclared identifier d:\diverse\lucru\visual studio 2010\projects\evilmonkeys\evilmonkeys\level.cpp 48 1 evilMonkeys
    Error 5 error C2065: 'y' : undeclared identifier d:\diverse\lucru\visual studio 2010\projects\evilmonkeys\evilmonkeys\level.cpp 49 1 evilMonkeys
    Error 6 error C2065: 'y' : undeclared identifier d:\diverse\lucru\visual studio 2010\projects\evilmonkeys\evilmonkeys\level.cpp 51 1 evilMonkeys


    -----------------------------------------------------------------------------------------------

    The error comes from this part of the code:

    void Level::createLevel(void)
    {
    for (int x = 0; x < width; x++)
    {
    for (int y = 0; y < height; y++);
    {
    int random = rand() % 100;

    //the error is starting on this line with the first 'y'
    if (y == 0 || y == height - 1 || x == 0 || x == width - 1)
    {
    level[y][x] = TILE_WALL;
    }
    else
    {
    if (random < 90 || (x < 3 && y < 3))
    level[x][y] = TILE_EMPTY;
    else
    level[x][y] = TILE_WALL;
    }
    }
    }
    }

    -----------------------------------------------------------------------------------------------
    I am using Microsoft Visual Studio 2010 and everything worked perfectly until I got this error. I searched all the files in the project for a fix, and saw for about 4 or 5 times the lesson again, hoping to spot something wrong, but I did it exactly like in the lesson. I don't know if it's a error from using a newer version of Visual Studio or because of me.

    Please some one help, because if I can't fix this error, I can't finish the EvilMonkeys lesson and project.
    (I have also attached an screenshot with the problem in VS2010, maybe it helps more)
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	VT2010error.jpg 
Views:	54 
Size:	281.1 KB 
ID:	72551  

  2. #2
    Join Date
    Aug 2005
    Location
    Washington for now..
    Posts
    25
    Code:
    void Level::createLevel(void)
    {
      for (int x = 0; x < width; x++)
      {
        for (int y = 0; y < height; y++);
        {
          int random = rand() % 100;
    
          //the error is starting on this line with the first 'y'
          if (y == 0 || y == height - 1 || x == 0 || x == width - 1)
          {
             level[y][x] = TILE_WALL;
          }
          else
          {
            if (random < 90 || (x < 3 && y < 3))
              level[x][y] = TILE_EMPTY;
            else
              level[x][y] = TILE_WALL;
          }
        }
      }
    }
    It appears the for loop that declares your y variable is immediately followed by a semi-colon. Please use the code tags in the future.

  3. #3
    Join Date
    Aug 2011
    Location
    Romania, Bucharest
    Posts
    5
    @DrepMagnus
    Hey mate thank you very much. I just don't know how could I miss that, because I searched all the cod very well, but it appears that I was still missing something. I am a beginner in C++

    I appreciate your help very much, thank you again.

  4. #4
    Join Date
    Jul 2008
    Location
    Portsmouth, England
    Posts
    436
    It's worth pointing out why that semicolon caused that error.

    Variables declared in the first part of a for loop have their scope limited to that statement. The for() part can be followed by a single statement or by a block. You've meant to follow it by a block, but the effect of putting the semicolon there is that the compiler thinks you have a single statement (a semicolon marks the end of a statement even if there's nothing before it) with a completely unrelated block of code after it.

    So even if your program had compiled, which it would if you'd declared "int x,y" at the top of the function, it wouldn't have worked.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •