#ifndef GUESSINGGAME_H #define GUESSINGGAME_H #include #include "clear.hpp" #include "getrandom.hpp" using std::cout; using std::cin; using std::endl; inline void Guess(int &input, const int count) { if (count != 20) cout << "This is guess " << count << ".\nEnter your guess: "; else cout << "\nLast chance! Enter your best guess: "; cin >> input; } inline void HighLow(const int random, const int input, const int count) { cout << "\n"; if (random < input) cout << input << " is greater than the number."; else if (random > input) cout << input << " is less than the number."; else cout << input << " is correct!"; } inline bool WinLoseAgain(const int random, const int input) { char again; if (random == input) { cout << "\nCongrats, you win!"; } else { cout << "\nOh no! You lost! The correct guess was: " << random; } cout << "\nWould you like to play again? (Y/N): "; cin >> again; if (again == 'Y') return true; else return false; } inline void GuessingGame() { const int random = GetRandom(1000, 1); int input = 0; int count = 1; ClearScreen(); cout << "*************************************************************\n"; cout << "Welcome to the guessing game!\nYou have 20 guesses to guess a number between 1-1000.\n"; while (input != random && count != 21) { Guess(input, count); HighLow(random, input, count); count++; } if (WinLoseAgain(random, input) == true) GuessingGame(); } #endif