Advertisement
Da_Gamer

Whacha man

Dec 9th, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.42 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. void create_numbers_to_guess(int guesses[], int arrSize);
  7. void provide_assistance(int guess, int answer);
  8. void clear_guessed_numbers(int guessed[], int arrSize);
  9.  
  10. int main ()
  11. {
  12.     string prompt = "Enter a number: ";
  13.     string help_prompt = "Would you like some assistance?";
  14.     string help_prompt_2 = "You have used up available assistance. Good luck!";
  15.  
  16.     string win_prompt = "Excellent! You win!";
  17.     string lose_prompt = "Unfortunately, probability has defeated you.";
  18.  
  19.     string instructions = "Press Ctrl + Z or Ctrl + D to end the game. Enter (number) 0 to get assistance. Enter a number and press Enter to input your guess.";
  20.  
  21.     int guessedInput = 0;
  22.     int answer = 0;
  23.     const int max_guesses = 1024;
  24.     int guessed_numbers[max_guesses];
  25.     int number_to_guess[max_guesses];  
  26.     int guesses_used = 0;
  27.  
  28.     const int total_lifelines = 256;
  29.     int lifelines_used = 0;
  30.  
  31.     cout << instructions << endl;
  32.  
  33.     create_numbers_to_guess(number_to_guess, max_guesses);
  34.  
  35.     for (int i = 0; i < max_guesses; ++i)
  36.     {
  37.         answer = number_to_guess[i];
  38.         guesses_used = 0;
  39.         lifelines_used = 0;
  40.         clear_guessed_numbers(guessed_numbers, max_guesses);
  41.         cout << answer << endl;
  42.         while (cin.good())
  43.         {
  44.             if (guesses_used == max_guesses)
  45.             {
  46.                 cout << lose_prompt << endl;
  47.                 cin.eof(); // set flag for cin to close and make while loop break;
  48.             }
  49.            
  50.             cout << prompt << endl;
  51.             cin >> guessedInput;
  52.  
  53.             if (guessedInput == answer)
  54.             {
  55.                 cout << win_prompt << endl;
  56.                 break;
  57.             }
  58.  
  59.             if (guessedInput == 0 && lifelines_used == total_lifelines)
  60.             {
  61.                 cout << help_prompt_2 << endl;
  62.             }
  63.             else if (guessedInput == 0)
  64.             {
  65.                 provide_assistance(guessedInput, answer);
  66.                 ++lifelines_used;
  67.             }
  68.  
  69.             guessed_numbers[guesses_used] = guessedInput;
  70.             ++guesses_used;
  71.  
  72.         }
  73.     }
  74.     return 0;
  75. }
  76.  
  77. void create_numbers_to_guess(int guesses[], int arrSize)
  78. {
  79.     for (int i = 0; i < arrSize; ++i)
  80.     {
  81.         int aGuess = rand() % 5;
  82.         if (aGuess == 0) { aGuess = 1; }
  83.         guesses[i] = aGuess;
  84.     }
  85. }
  86.  
  87. void provide_assistance(int guess, int answer)
  88. {
  89.     string high_prompt = "Go higher.";
  90.     string low_prompt = "Go lower.";
  91.  
  92.     if (guess > answer)
  93.     {
  94.         cout << low_prompt << endl;
  95.     }
  96.     else if (guess < answer)
  97.     {
  98.         cout << high_prompt << endl;
  99.     }
  100. }
  101.  
  102. void clear_guessed_numbers(int guessed[], int arrSize)
  103. {
  104.     for (int i = 0; i < arrSize; ++i)
  105.     {
  106.         guessed[i] = 0;
  107.     }
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement