Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. #include <iostream>
  2. #include <time.h>
  3. #include <stdlib.h>
  4. #include <ctime>
  5.  
  6.  
  7. //unsigned int validInput() {
  8. //
  9. // while (true) {
  10. //
  11. // unsigned int userInputF{};
  12. // std::cout << "Please enter a number between 1 and 100: ";
  13. // std::cin >> userInputF;
  14. //
  15. // if (userInputF < 1 || userInputF > 100 || userInputF == NULL) {
  16. //
  17. // std::cout << "Incorrect response, please enter a number between 1 and 100: ";
  18. // std::cin >> userInputF;
  19. //
  20. // }
  21. // else {
  22. //
  23. // break;
  24. // return userInputF;
  25. // }
  26. // }
  27. //}
  28.  
  29. unsigned int randomNumberGen() {
  30.  
  31. srand(time(NULL)); //creates seed based on the local computer time
  32.  
  33. unsigned int randomNumberF = rand() % 100 + 1;
  34.  
  35. return randomNumberF;
  36. }
  37.  
  38. int playTournament() {
  39.  
  40. unsigned int userInput = 0;
  41. unsigned int randomNumber = randomNumberGen();
  42. unsigned int const constNumberTries = 8;
  43. unsigned int numPlayerTries = 0;
  44. unsigned int const constNumberWins = 3;
  45. unsigned int numberWins = 0;
  46.  
  47.  
  48. while (numberWins < constNumberWins) { //--checks the number of rounds won
  49.  
  50. for (unsigned int i = 0; i < constNumberTries; i++) { //--makes sure player doesn't go over the try limit
  51.  
  52. std::cout << "You have won " << numberWins << "/" << "3 rounds." << std::endl;
  53.  
  54. for (numPlayerTries = 0; numPlayerTries < constNumberTries; numPlayerTries++) {
  55.  
  56. std::cout << "Please enter a number between 1 - 100: ";
  57. std::cin >> userInput;
  58.  
  59. CHECKIF:if (userInput < 1 || userInput > 100 || userInput == NULL) {
  60.  
  61. std::cout << "Incorrect response, please enter a number between 1 and 100: ";
  62. std::cin >> userInput;
  63.  
  64. } else {
  65.  
  66. if (userInput > randomNumber) {
  67.  
  68. std::cout << "Your guess was too high, try a different number: ";
  69. std::cin >> userInput;
  70. goto CHECKIF;
  71. }
  72. else if (userInput < randomNumber) {
  73.  
  74. std::cout << "Your guess was too low, try a different number: ";
  75. std::cin >> userInput;
  76. goto CHECKIF;
  77. }
  78. else if (userInput == randomNumber) {
  79.  
  80. std::cout << "Congratulations, you guessed the correct number!" << std::endl;
  81. std::cin >> userInput;
  82. numberWins++;
  83. break;
  84. }
  85.  
  86. if (numPlayerTries > constNumberTries) {
  87.  
  88. std::cout << "Sorry but you failed to guess " << randomNumber << "." << std::endl;
  89. }
  90.  
  91. }
  92.  
  93. }
  94.  
  95. }
  96.  
  97. }
  98.  
  99. return 0;
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement