Triple X final

#include <iostream>
#include <ctime>
using namespace std;

void congrats()
{
    cout<<"\nCongratulations!! You successfully hacked the server!!!!"<<endl;
}

void GameIntro(int Difficulty)
{
    cout<<"\n \nYou are a secret agent breaking into a server room !"<<endl;
    cout<<"You have to get the right combination in order to break in the system....."<<endl;
    cout<<"Your Difficulty level is "<<Difficulty<<endl;

}

bool PlayGame(int Difficulty)
{
    GameIntro(Difficulty);
    
    int CodeA=rand() % Difficulty + Difficulty; 
    int CodeB=rand() % Difficulty + Difficulty; 
    int CodeC=rand() % Difficulty + Difficulty;
    int CodeSum,CodeProduct;

    CodeSum = CodeA + CodeB + CodeC;
    CodeProduct = CodeA * CodeB * CodeC;


    cout<<endl;
    cout<<"* There is a 3 digit code"<<endl;
    cout<<"* The sum of the digits is: "<<CodeSum<<endl;
    cout<<"* The product of the digits is: "<<CodeProduct<<endl;
    cout<<endl;

    int GuessA, GuessB, GuessC;
    int GuessSum, GuessProduct;


    cout<<"Enter Numbers"<<endl;
    cin>> GuessA >> GuessB >> GuessC;

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

    if(GuessSum == CodeSum && GuessProduct == CodeProduct)
    {
        cout<<"\n***Good work agent!! You got the file ! ***";
        return true;
    }

    else
    {
        cout<<"\n *** Thats not correct!! Be careful Agent!!!***";
        return false;
    }


}


int main()
{
    srand(time(NULL));
    int LevelDifficulty = 1;
    int const MaxDifficulty = 5;
    while(LevelDifficulty <= MaxDifficulty)
    {

    bool bLevelComplete = PlayGame(LevelDifficulty);
    cin.clear();  //Clears errors
    cin.ignore(); //Discards the buffer

     if(bLevelComplete)
    {
        cout<<"\nYour level will be increased"<<endl;
        LevelDifficulty++;
    }

    else
    {
        cout<<"\nYour level is not increased try again..."<<endl;
    }


    }


    congrats();


    

    return 0;
}


1 Like

Hi Aksh. Welcome to the Community and hope you’re enjoying the course so far.

Thanks for sharing and good luck with the rest of the course as well.

Privacy & Terms