Need Help with this xxx game Code!

// xxx_NumberGame.cpp : This file contains the ‘main’ function. Program execution begins and ends there.
//

#include

void PlayIntro(int Difficulty)
{
std::cout << "\nYou are secret agent, Breaking into the level " << Difficulty;
//We have used endl function to end the line. we can also use \n to get the same output but this seems more standard and correct
std::cout << “\nYou need to enter the correct codes to continue…”;
std::cout << std::endl;
}

bool PlayGame(int Difficulty)
{

PlayIntro(Difficulty);


int NumA = 4;
int NumB = 6;
int NumC = 7;

int CodeSum = NumA + NumB + NumC;

int CodeProd = NumA * NumB * NumC;



std::cout << "\n+There are three numbers in the code ";
std::cout << "\n+The numbers add upto " << CodeSum;
std::cout << "\n+Product of these three numbers is " << CodeProd;
std::cout << "\n";
std::cout << "\nGo ahead and enter the three numbers\n";


int GuessA, GuessB, GuessC;

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

int GuessSum;
int GuessProduct;

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

if (GuessSum == CodeSum && GuessProduct == CodeProd)
{

    std::cout << "\n******Correct Guess Genius!!!!! You are Adavancing to the next level!!*******";
    return true;
}
else
{

    std::cout << "\n!!!!OOPPPPSSS You are going to die#####";
    return false;
}

}

int main()
{
int LevelDifficulty = 1;
int const MaxLevel = 3;

while (LevelDifficulty <= MaxLevel) //Loop Game untill all level gets completed
{
    bool bLevelComplete = PlayGame(LevelDifficulty);

    std::cout << std::endl;

    PlayGame(LevelDifficulty);

    std::cin.clear();
    std::cin.ignore();

    if (bLevelComplete)
    {
        ++LevelDifficulty;

    }
}

std::cout << "Congrats Agent You fucking won!!!";
return 0;

}

Can Someone please go through this code and explain me why do I have to enter correct code twice to advance to the next level!!! Please this is killing me. I am noob :((((((((((((((((((((

    bool bLevelComplete = PlayGame(LevelDifficulty);

    std::cout << std::endl;

    PlayGame(LevelDifficulty);

You have PlayGame() called twice in the loop so each loop you play the game twice. Remove the second one.

To improve your skills debugging, you already knew “that you have to enter the code twice to advance”. All you have to do then is look at where that is done and all code involving that. Then you determine why. You had the first part with testing and finding the bug, so that’s great.

Of course, if that was the desired effect then the bug would probably be in PlayGame() function code. So, these are things that need to be thought about.

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

Privacy & Terms