Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <time.h>
- #include <stdlib.h>
- #include <ctime>
- //unsigned int validInput() {
- //
- // while (true) {
- //
- // unsigned int userInputF{};
- // std::cout << "Please enter a number between 1 and 100: ";
- // std::cin >> userInputF;
- //
- // if (userInputF < 1 || userInputF > 100 || userInputF == NULL) {
- //
- // std::cout << "Incorrect response, please enter a number between 1 and 100: ";
- // std::cin >> userInputF;
- //
- // }
- // else {
- //
- // break;
- // return userInputF;
- // }
- // }
- //}
- unsigned int randomNumberGen() {
- srand(time(NULL)); //creates seed based on the local computer time
- unsigned int randomNumberF = rand() % 100 + 1;
- return randomNumberF;
- }
- int playTournament() {
- unsigned int userInput = 0;
- unsigned int randomNumber = randomNumberGen();
- unsigned int const constNumberTries = 8;
- unsigned int numPlayerTries = 0;
- unsigned int const constNumberWins = 3;
- unsigned int numberWins = 0;
- while (numberWins < constNumberWins) { //--checks the number of rounds won
- for (unsigned int i = 0; i < constNumberTries; i++) { //--makes sure player doesn't go over the try limit
- std::cout << "You have won " << numberWins << "/" << "3 rounds." << std::endl;
- for (numPlayerTries = 0; numPlayerTries < constNumberTries; numPlayerTries++) {
- std::cout << "Please enter a number between 1 - 100: ";
- std::cin >> userInput;
- CHECKIF:if (userInput < 1 || userInput > 100 || userInput == NULL) {
- std::cout << "Incorrect response, please enter a number between 1 and 100: ";
- std::cin >> userInput;
- } else {
- if (userInput > randomNumber) {
- std::cout << "Your guess was too high, try a different number: ";
- std::cin >> userInput;
- goto CHECKIF;
- }
- else if (userInput < randomNumber) {
- std::cout << "Your guess was too low, try a different number: ";
- std::cin >> userInput;
- goto CHECKIF;
- }
- else if (userInput == randomNumber) {
- std::cout << "Congratulations, you guessed the correct number!" << std::endl;
- std::cin >> userInput;
- numberWins++;
- break;
- }
- if (numPlayerTries > constNumberTries) {
- std::cout << "Sorry but you failed to guess " << randomNumber << "." << std::endl;
- }
- }
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement