Help with Unreal CPP TripleX game (Please Help ASAP)

#include <iostream>
#include <curses.h>
#include <ctime>

void PrintIntroduction(int Difficulty, bool bComplete)
{
    std :: cout << "Hello and Welcome to Jewel Thief!\n";
    std :: cout << "In this game you have to find random number codes to get to the next level. There are some rules.\n\n";

    std :: cout << "1. This game contains 10 levels. You can always replay the game and it will be different each time because the codes are randomised.\n";
    std :: cout << "2. You have to enter each number of the code with spaces. For example, 1 2 3 not 123.\n";
    std :: cout << "3. If you accidentally type in a letter or the code without the spaces, just restart the game.\n";
    std :: cout << "4. The game will give you clues about the code and you have to guess it based on that.\n\n";

    std :: cout << "Lets Play!\n\n";

    std :: cout << "You are a Jewel Thief, and you are stealing the biggest Diamond on Earth!";
    std :: cout << std :: endl;
    std :: cout << "There is a door in front of you with a keypad and the sign Level 1, it seems that it wants a 3 digit code...";
    std :: cout << std :: endl;
}
void PlayGame(int Difficulty, bool bComplete)
{
 
    
    int CodeA =rand() % Difficulty + Difficulty;
    int CodeB =rand() % Difficulty + Difficulty;
    int CodeC =rand() % Difficulty + Difficulty;
    
    int CodeSum = CodeA + CodeB + CodeC;
    int CodeProduct = CodeA * CodeB * CodeC;

    std :: cout << std :: endl;
    std :: cout<< "Clues :\n";
    std :: cout << "* The sum of the numbers is " << CodeSum;
    std :: cout << std :: endl;
    std :: cout << "* The product of the numbers is \n" << CodeProduct;

    int GuessA, GuessB, GuessC, GuessSum, GuessProduct;
    std :: cout << std :: endl;
    std :: cout << "Enter the Code : ";
    
    std :: cin >> GuessA;
    std :: cin >> GuessB;
    std :: cin >> GuessC;

    GuessSum = GuessA + GuessB + GuessC;
    GuessProduct = GuessA * GuessB * GuessC;
    if (GuessSum == CodeSum && GuessProduct == CodeProduct && Difficulty < 10)
    {

    std :: cout << "\n\nThe Door Opens! But there is another door with the sign of Level "<< Difficulty;
    bComplete = true;
     }
    else if (GuessSum == CodeSum && GuessProduct == CodeProduct && Difficulty == 10)
    {
    std :: cout << "You opened the Final Door! You steal the diamond and live the rest of your life happily as a Billionaire!"  ;
    }
    else
    {
    std :: cout << "\nThe Alarms starts blaring and you are quickly caught by the police! You spend the rest of your life in prison.";
    std :: cout << "\nGAME OVER!!!";
    bComplete = false;
    }
    
}
int main()
{
    srand(time(NULL));
  int LevelDifficulty = 1;
  bool bComplete;

  PrintIntroduction(LevelDifficulty, bComplete);
  while (LevelDifficulty <= 10)
  {
      PlayGame(LevelDifficulty, bComplete);
      ++LevelDifficulty;
  }

  

  std :: cout << "Thank you for Playing! Hope you enjoyed!\n";
  return 0;

}

Hey guys, this is from the unreal cpp triple x game.
When i give the wrong answer the game displays the wrong message as expexcted but it still gives clues and asks the next question. How do i make it exit? Please help me.

    else if (GuessSum == CodeSum && GuessProduct == CodeProduct && Difficulty == 10)
    {
    std :: cout << "You opened the Final Door! You steal the diamond and live the rest of your life happily as a Billionaire!"  ;
    }
    else
    {
    std :: cout << "\nThe Alarms starts blaring and you are quickly caught by the police! You spend the rest of your life in prison.";
    std :: cout << "\nGAME OVER!!!";
    bComplete = false;
    }

You aren’t returning anything in this section.
Instead of bComplete try

return = false;

Looks like you are still going through the course so parts of your code will likely change anyway.

For example, this is what I have in that part of the code

    if (Difficulty != MaxDifficulty && GuessSum == CodeSum && GuessProduct == CodeProduct)
    {
        GuessResult = "That's right!";
        PrintNextLevelIntro(Difficulty);
    }
    else if (GuessSum != CodeSum || GuessProduct != CodeProduct)
    {
        std::cout << "That's incorrect! Neural seepage is irreversable and you have minutes to live.\n \n";
        std::cout << "Try again! \n \n";
        PrintIntroduction();
        return false;
    }
    else
    {
        return true;
    }

Thanks, I have already completed the course.
So i should delete bComplete = false; and type in return false; instead?

1 Like

Ahhh my bad, when I saw the max difficulty level where you have it I thought I remembered having it there until a later lecture.

Just looks like you did it in a different way which is just as valid.

I would comment out your bComplete line and try return and see if it helps.

I tried it, still doesnt work

Can you please send your whole code?

  • void PrintIntroduction(int Difficulty, bool bComplete)
    
    Difficulty and bComplete are not used at all in this function. Remove them.
  • CodeA/B/C, CodeProduct, and CodedSum can all be const.
    C++ Core Guidelines
  • GuessSum and and GuessProduct should be declared on the line they are initialised with a value.
    C++ Core Guidelines
    C++ Core Guidelines
  • if (GuessSum == CodeSum && GuessProduct == CodeProduct && Difficulty < 10)
    {
        //...
        bComplete = true;
    }
    else if (GuessSum == CodeSum && GuessProduct == CodeProduct && Difficulty == 10)
    {
        //...
    }
    else
    {
        //...
        bComplete = false;
    }
    
    The value that is passed to this function is a copy of the argument. The variable bComplete inside main is unitialised and will never be given a value. The one inside PlayGame is never read. With clang-tidy (static analysis tool) I get the following warning inside the if and else statements.

    warning GC1A2668F: Value stored to ‘bComplete’ is never read [clang-analyzer-deadcode.DeadStores]