Advertisement
Guest User

Untitled

a guest
Jul 20th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3.  
  4. void PrintIntroduction(int Difficulty)
  5. {
  6. std::cout << "\n You are a secret agent breaking into a level " << Difficulty;
  7. std::cout << " secure server room.\n You need to enter the correct code to continue.\n\n";
  8. }
  9.  
  10. bool PlayGame(int Difficulty)
  11. {
  12.  
  13. PrintIntroduction(Difficulty);
  14.  
  15. // Welcome to the numbers game
  16. const int CodeA = rand() % Difficulty + 1;
  17. const int CodeB = rand() % Difficulty + 1;
  18. const int CodeC = rand() % Difficulty + 1;
  19.  
  20. const int CodeSum = CodeA + CodeB + CodeC;
  21. const int CodeProduct = CodeA * CodeB * CodeC;
  22.  
  23. // Print CodeSum and CodeProduct to the terminal
  24.  
  25. std::cout << "\n + There are 3 numbers in the code";
  26. std::cout << "\n + The codes add up to " << CodeSum;
  27. std::cout << "\n + The codes multiply to give " << CodeProduct << std::endl;
  28.  
  29. // Store Player Guess
  30. int GuessA, GuessB, GuessC;
  31. std::cin >> GuessA >> GuessB >> GuessC;
  32.  
  33. // Check if the players guess is correct
  34. int GuessSum = GuessA + GuessB + GuessC;
  35. int GuessProduct = GuessA * GuessB * GuessC;
  36.  
  37. if(GuessSum == CodeSum && GuessProduct == CodeProduct)
  38. {
  39. std::cout << "Correct proceed" << std::endl;
  40. return true;
  41. }
  42. else
  43. {
  44. std::cout << "Access denied\n";
  45. return false;
  46. }
  47. }
  48. int main()
  49. {
  50. srand(time(NULL)); // Create new random sequence based on the time of day
  51.  
  52. int LevelDifficulty = 1;
  53. int const MaxDifficulty = 5;
  54.  
  55. while (LevelDifficulty <= MaxDifficulty) // Loop until all the levels are completed
  56. {
  57. bool bLevelComplete = PlayGame(LevelDifficulty);
  58. std::cin.clear(); //Clears any errors
  59. std::cin.ignore(); // Discard the buffer
  60.  
  61. if (bLevelComplete)
  62. {
  63. ++LevelDifficulty;
  64. }
  65.  
  66. }
  67. std::cout << "Well done you're in! Get the files and leave";
  68. return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement