Triplex game

#include <iostream>



void PrintIntroduction(int Difficulty)
{
    std::cout << "Greetings traveller, so you have come for the riddle? It is " << Difficulty;
    std::cout << "\n Knocks of strength, come forth and I shall grant you a chance at it\n\n";
}


bool PlayGame(int Difficulty)
{

    PrintIntroduction(Difficulty);
    
    
    
    
    const int CodeA = 4;
    const int CodeB = 3;
    const int CodeC = 2;
   
    const int CodeProduct = CodeA * CodeB * CodeC;
    const int CodeSum = CodeA + CodeB + CodeC;



    //Print CodeSum and CodeProduct to the terminal
    std::cout <<"+ There are three numbers in the code\n";
    std::cout <<"+ The codes add-up to: "<< CodeSum;
    std::cout <<"\n+ the codes multiply to give: " << CodeProduct;


    // Store player guess

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


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

    //Check if players guess is correct
    if (GuessSum == CodeSum && GuessProduct == CodeProduct)
    {
        std::cout << "\n You Win traveller, congratulations";
        return true;
    }
    
    else
    {
        std::cout << "\n NO! You are banished from these realms!";
        return false;
    }


}




int main()
{


    int LevelDifficulty = 1;  
    while (true)
    {

    bool bLevelComplete = PlayGame(LevelDifficulty);
    std::cin.clear();
    std::cin.ignore();
        if (bLevelComplete)
        {
            ++LevelDifficulty;

        }


    }   


    
    return 0;
}```

This code starts an endless loop of the code, what could be wrong with it?

That’s what is supposed to happen at this stage. That’s what while(true) does. It’s an infinite loop.

Privacy & Terms