Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.12 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3. #include <cstdlib>
  4.  
  5. const int LOWER_NUMBER_BOUND = 0;
  6. const int UPPER_NUMBER_BOUND = 9;
  7. const int GUESS_ATTEMPTS = 5;
  8. // Here's what my program looks like:
  9. int main()
  10. {
  11. int userGuess;
  12. int numberToGuess;
  13. int guessAttemptsRemaining;
  14. int playAgain = 0;
  15.  
  16. srand(time(0));
  17.  
  18. do
  19. {
  20. system("CLS");
  21. std::cout << "------------------------------\n";
  22. std::cout << "Welcome to Guess that number!\n";
  23. std::cout << "------------------------------\n";
  24. std::cout << "Round 1.\n";
  25.  
  26. numberToGuess = rand() % 5;
  27. guessAttemptsRemaining = GUESS_ATTEMPTS;
  28.  
  29. do
  30. {
  31.  
  32. userGuess = -1;
  33.  
  34. while (userGuess < 0 || userGuess > 5)
  35. {
  36. std::cout << "Guess a number less than 5: ";
  37. if (!(std::cin >> userGuess))
  38. {
  39. std::cin.clear();
  40. std::cin.ignore(10000, '\n');
  41. }
  42. }
  43.  
  44. --guessAttemptsRemaining;
  45. std::cout << "You picked: " << userGuess << ".\n";
  46.  
  47. if (userGuess != numberToGuess)
  48. {
  49. // std::cout << "Incorrect, try again\n";
  50.  
  51. if (guessAttemptsRemaining > 0)
  52. {
  53. std::cout << "Incorrect, try again " << guessAttemptsRemaining << " guess(es) remaining.\n";
  54. }
  55. else
  56. {
  57. std::cout << "Game Over\n";
  58.  
  59. }
  60.  
  61. }
  62. else
  63. {
  64. std::cout << "Correct! The number was \n";
  65.  
  66. std::cout << "Round 2.\n";
  67. do
  68. {
  69.  
  70. userGuess = -1;
  71.  
  72. while (userGuess < 0 || userGuess > 5)
  73. {
  74. std::cout << "Guess a number less than 5: ";
  75. if (!(std::cin >> userGuess))
  76. {
  77. std::cin.clear();
  78. std::cin.ignore(10000, '\n');
  79. }
  80. }
  81.  
  82. --guessAttemptsRemaining;
  83. std::cout << "You picked: " << userGuess << ".\n";
  84.  
  85. if (userGuess != numberToGuess)
  86. {
  87. // std::cout << "Incorrect, try again\n";
  88.  
  89. if (guessAttemptsRemaining > 0)
  90. {
  91. std::cout << "Incorrect, try again " << guessAttemptsRemaining << " guess(es) remaining.\n";
  92. }
  93. else
  94. {
  95. std::cout << "Game Over\n";
  96.  
  97. }
  98.  
  99. }
  100. else
  101. {
  102. std::cout << "Correct! The number was \n";
  103. //round number, random boundary, random number, guessAttemptsRemaining need to change
  104.  
  105. }
  106.  
  107. } while (guessAttemptsRemaining > 0);
  108.  
  109. } while (playAgain == 1);
  110.  
  111. return 0;
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement