My Triple X game so far (before the rand thing)

Note that I didn’t wanted to show the usual success message just before congratulating the player for finishing the game, so I used elsif where appropriate.

PS: past is making a strange double space between lines or something.

//preprocessor libraries

#include

void PrintIntroduction(int Difficulty)

 { 

 std::cout << "\n\n This is Triple-x, the guess code game!!!!  \n ()()()()()() XXX ()()()()()() \n";

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

 std::cout <<" secure server room... \nYou need to enter the correct codes to continue \n\n";

      }

bool PlayGame(int Difficulty)

 {

      

 PrintIntroduction(Difficulty);

      

 //Declare and initialize 3 number code

 int CodeA = 4;

 int CodeB = 1;

 int CodeC = 1;

//declare and initialize sum and product

 int CodeSum = CodeA + CodeB + CodeC;

 int CodeProd = CodeA * CodeB * CodeC;

//print sum and product

  std::cout << std::endl;

 std::cout << "\n there are 3 numbers in the code";

 std::cout << "\n It adds up to " <<  CodeSum;

 std::cout << "\n Their product is " << CodeProd << std::endl;

 int GuessA, GuessB, GuessC;

 std::cin >> GuessA;

 std::cin >> GuessB;

 std::cin >> GuessC;

 int GuessSum = GuessA + GuessB + GuessC;

 int GuessProd = GuessA * GuessB * GuessC;

//Return booleans to check player progress

 if (GuessSum == CodeSum && GuessProd == CodeProd && Difficulty !=5)

 {   std::cout << "\n Genius, you got it! go to next level";

      return true;

 }else if (GuessSum == CodeSum && GuessProd == CodeProd)

 {

      return true;

 }else 

 {std::cout << "\n Meh, you failed! Try again";

      return false;

 }

 }

// start here

int main()

 {

 

 int LevelDifficulty = 1;

 int const MaxDifficulty = 5;

 while (LevelDifficulty <= MaxDifficulty)

 {

      bool bLevelComplete = PlayGame(LevelDifficulty);



      std::cin.clear();//clear any erros

      std::cin.ignore();//discards the buffer

 if (bLevelComplete)

 {

      ++LevelDifficulty;

 }

 

 }

    

 std::cout << "Congratilations, you finished the game";

           

 return 0; 

  }

Most important is first step!

Privacy & Terms