Lynix_

Bull/Cow Game C++ v2

Jul 30th, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.01 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. void PrintIntro();
  7. void PlayGame();
  8. string GetGuess();
  9. bool PlayAgain();
  10.  
  11. int main(int number)
  12. {
  13.     PrintIntro();
  14.  
  15.     PlayGame();
  16.  
  17.     PlayAgain();
  18.     return 0;
  19. }
  20.  
  21. void PlayGame()
  22. {
  23.     int Tries = 5;
  24.     for (int count = 0; count < Tries; count++)
  25.     {
  26.         GetGuess();
  27.        
  28.     }
  29. }
  30.  
  31. void PrintIntro()
  32. {
  33.     constexpr int WordLength = 5;
  34.     cout << "Welcome to Bulls and Cows!" << endl;
  35.     cout << "Can you guess the word I'm thinking of?..  It's a ";
  36.     cout << WordLength;
  37.     cout << " letter word" << endl;
  38.     return;
  39. }
  40.  
  41. string GetGuess()
  42. {
  43.     string Guess;
  44.     cout << "Your guess: ";
  45.     getline(cin, Guess);
  46.     cout << "You guessed: ";
  47.     cout << Guess << endl;
  48.     cout << endl;
  49.     return Guess;
  50. }
  51.  
  52. bool PlayAgain()
  53. {
  54.     cout << "Would you like to play again?";
  55.     string Response = "";
  56.     getline(cin, Response);
  57.     cout << "First char: " << (Response[0] == 'y' || 'Y');
  58.     cout << endl;
  59.     return (Response[0] == 'y') || (Response[0] == 'Y');
  60. }
Advertisement
Add Comment
Please, Sign In to add comment