My tripplex game at the end

this is my end result of the tripplex game
#include

#include

void PrintIntroduction(int Difficulty)

{

//this is the start of the game

std::cout<< "\n\nyou are a secret agent into a level " << Difficulty;



std::cout<<" security enter correct code to comtinue...\n\n";

}

bool PlayGame(int Difficulty)

{

PrintIntroduction(Difficulty);

//declaring variables

const int CodeA=rand()%Difficulty+Difficulty;

const int CodeB=rand()%Difficulty+Difficulty;

const int CodeC=rand()%Difficulty+Difficulty;

const int CodeSum = CodeA + CodeB + CodeC;

const int CodeProduct =CodeA * CodeB * CodeC;

std::cout<< std::endl;

std::cout<< "there are three numbers in the code";

std::cout<< "\nthe codes ads upto :"<< CodeSum ;

std::cout<<"\nthe multiplication of the codes is:" << CodeProduct;

std::cout<< std::endl;\

//store player guess

int GuessA, GuessB, GuessC;

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

std::cout<< std::endl;

int GuessSum=GuessA + GuessB + GuessC;

int Guessproduct=GuessA * GuessB * GuessC;

//check if players guess is correct

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

{

    std::cout<<"\n congrats you move to the next level";

    return true;

}

else

{

    std::cout<<"\nyou lose\n";

    std::cout<<"\n you have to retry this level ";

    return false;



}

}

int main()

{

srand(time(NULL));

int LevelDifficulty=1;

int const MaxLevel=5;

while (LevelDifficulty<=MaxLevel)

{

    bool blevelcomplete = PlayGame(LevelDifficulty);

    std::cin.clear();

    std::cin.ignore();

    if (blevelcomplete)

    {

        //inclrease the difficulty

        ++LevelDifficulty;

    }

    

}

std::cout<<"\nyou win !";

return 0;

}

1 Like

Keep up the good work.

Privacy & Terms