Hi All, Any ideas why? 'bLevelComplete': undeclared identifier

I’ve been through the tutorials again and again but still my code will not compile and I get this message.
Hi All, Any ideas why I’m getting this message? ‘bLevelComplete’: undeclared identifier.

#include
void PrintIntroduction(int Difficulty)
{

std::cout << "\nYou are stuck, However, to break out of this stuckness version: " << Difficulty;
std::cout << "you can manifest 3 numbers to break the vortex\n\n";
std::cout << "OK manafest the numbers...\n";

}
bool PlayGame(int Difficulty)
{
PrintIntroduction(Difficulty);

int CodeA = 4;
int CodeB = 3;
int CodeC = 2;

int CodeSum = CodeA + CodeB + CodeC;

int CodeProduct = CodeA * CodeB * CodeC;

std::cout << "There are 3 Numbers in the code";

std::cout << "\nThey add-up to: " << CodeSum;

std::cout << "\nThe numbers multiply to give: " << CodeProduct << std::endl;

int GuessA, GuessB, GuessC;

std::cin >> GuessA >> GuessB >> GuessC;



int GuessSum = GuessA + GuessB + GuessC;

int GuessProduct = GuessA * GuessB * GuessC;

//Check if player is correct

if (GuessSum == CodeSum && GuessProduct == CodeProduct)

{

    std::cout << "You Win!\n";

    return true;

}

else

{

    std::cout << "You Lose !\n\n\n\n";

    return false;

}

}

int main()

{

int LevelDifficulty = 1;

const int MaxDifficulty = 5;

while (LevelDifficulty <= MaxDifficulty) //Looop game until all levels completed

{

    bool bLevelComplete = PlayGame(LevelDifficulty);

    std::cin.clear(); //Clears any errors

    std::cin.ignore();//Discards the buffer

}

    if (bLevelComplete)

    {

        //Increase the level difficulty

        ++LevelDifficulty;      

    }

return 0;

}

Ah yes I see it now. You declare bool bLevelComplete inside of a while loop and then try to access that variable out of scope with the next if check. I think
"bool bLevelComplete = false; "
should be above the while loop in the main function,
then it can just say

“bLevelComplete = PlayGame(LevelDifficulty);”
in the while loop.

Cheers,
Tele

1 Like

I think I’ve figured it out. One of my curly brackets was in the wrong place

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms