#1. Add functionality to store the guesses the user makes in an array up to a maximum number of guesses stored in a constant.
#2. Display the list of guesses after the correct guess has been made.
#3. The list will be stored in an array of objects from a new class you create called Guess.
#4. Create three other classes in addition to Guess: High, Low, and Correct. DONE#5. These three will inherit from Guess.
#6. The array will use inheritance and polymorphism to display the guess made and a string of whether it was high, low, or correct for each guess.
#7. The high, low, or correct string needs to come from a method in these classes.
#8. Allow the user to decide if he or she wants to play another game. DONE
#include <iostream> // Used to produce input and output information.
#include <cstdlib> // This header is used to produce the random number generator function.
#include <ctime> // Header used to help with the production of random numbers.
#include <string> // Header used to allow string usage.
using namespace std; // Allows the use of cout and cin without having to type std in front of them everytime.
class GuessingGame
{
public:
GuessingGame(int seed)
{
srand(seed);
m_variable = rand() % (maxRandomNumber - minRandomNumber + 1) + minRandomNumber; // Part two of random number generator.
}
int storedRandomNumber()
{
return m_variable;
}
void regenerate()
{
m_variable = rand() % (maxRandomNumber - minRandomNumber + 1) + minRandomNumber;
}
static const int maxRandomNumber = 100;
static const int minRandomNumber = 1;
int m_variable;
};
class Guess(guessArray[10]);
{
};
class High
{
};
class Low
{
};
class Correct
{
};
int main ()
{
int userGuess = 0; // users guess of the random number
// Create random number
cout << "Welcome to My Number Generator Game" << endl; // output
cout << "The object of the game is to guess a number between 1 and 100" << endl << endl; // output
GuessingGame newGame(time(NULL));
newGame.storedRandomNumber();
bool playAgain=true; // Boolean expression used to offer the ability to play the game again.
while(playAgain)
{
newGame.regenerate();
while (userGuess != newGame.m_variable) // Loops forever, or until user finds the number.
{
int guessArray[10];
userGuess = guessArray[0]++;
cout << "Please enter your guess between 1 and 100: " ; // output
cin >> userGuess; // Input - User to enter a guess between 1 and 100
cout << "\n";
if(userGuess > newGame.maxRandomNumber || userGuess < newGame.minRandomNumber)
{
cout << "Please stay within the parameters of guesses between 1 and 100!" << endl;
continue;
}
if(userGuess > newGame.m_variable)
{
cout << "Your guess of " << userGuess << " is too high, guess lower" << endl << endl;
continue;
}
if(userGuess < newGame.m_variable)
{
cout << "Your guess of " << userGuess << " is too low, guess higher" << endl << endl;
continue;
}
if(userGuess = newGame.m_variable)
{
cout << "Congratulations, you are CORRECT with your guess of " << userGuess << " !" << endl << endl;
char again;
cout << "Do you want to play again? Enter y for yes or n for no: " ;
cin >> again;
cout << "\n";
if(again != 'y')
{
playAgain = false;
cout << endl << "Thank you for playing My Number Generator Game! " << endl << endl;
continue;
}
else(again = 'y');
{
playAgain = true;
}
}
}
}
string yourName;
cout << "Please type your first name and press enter. " ; // output
cin >> yourName; // Input - User to enter in their first name
return 0;
}