TripleX Incremental Difficulty seems not working in my code

Hi, it seems like my LevelDifficulty is not incrementing up, I don’t know which is wrong with my code. can you guys help me? thanks

#include <iostream> // Preprocessor directive

void PrintIntro(int Difficulty) {
    std::cout << "\n\n +++++ START +++++ \n\n";
    std::cout << "+ Level " << Difficulty;
}

bool PlayGame(int Difficulty) {

    PrintIntro(Difficulty);

    // Print intro message to the terminal
    std::cout << "\n\n+ Hello stranger,";
    std::cout << "\n+ You see a lock code to open the door.";
    std::cout << "\n+ You need to enter the correct code to continue...\n\n";

    // Declare 3 number code
    const int CodeA = 4;
    const int CodeB = 3;
    const int CodeC = 5;


    // Declare sum and product
    int CodeSum = CodeA + CodeB + CodeC;
    int CodeProduct = CodeA * CodeB * CodeC;

    std::cout << "+ All you need to do is to match the add up number to this: " << CodeSum << std::endl;
    std::cout << "+ And match the multiplication number into this result: " << CodeProduct << std::endl;

    // Store player guess
    int GuessA, GuessB, GuessC;
    std::cout << "\n+ Well, let's try input the code I guess...\n";
    std::cin >> GuessA >> GuessB >> GuessC;
    std::cout << "+ You have entered the code number: " << GuessA << ", " << GuessB << " and " << GuessC;

    int GuessSum = GuessA + GuessB + GuessC;
    int GuessProduct = GuessA * GuessB * GuessC;


    std::cout << "\n+ The add up result for your code input is: " << GuessSum;
    std::cout << "\n+ And the result for multiplication is: " << GuessProduct;

    // Check if the player guess is correct
    if(GuessSum == CodeSum && GuessProduct == CodeProduct) {

        std::cout << "\n+ You have entered the correct code combination, congratulations!";
        return true;

    } else {
        std::cout << "\n+ Sorry, you just entered the wrong code combination, I can't help you further, bye :(";
        return false;
    }

}

int main() // The main function to encapsulate all the codes
{   
   while (true)
   {

    int LevelDifficulty = 1;
       
    bool bLevelComplete = PlayGame(LevelDifficulty);
    std::cin.clear(); // Clears any error
    std::cin.ignore(); // Discard the buffer

    if (bLevelComplete)
    {
        ++LevelDifficulty;
    }
    
   }
   
    return 0;
}

Change it to the following and you will find it incrementing (at least as long as true (clarification: from PlayGame()) gets returned at some point and there’s not another issue in there).

   int LevelDifficulty = 1;

   while (true)
   {

You declared your “LevelDifficulty” variable into your while loop, declare it within your main fonction instead and it should fix the problem

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

Privacy & Terms