#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;
}
Comments
Ask a specific question, this is not a repository for homeworks.

Crap, I thought I had my question on that last post but apparently not. I'm wondering how to correctly link an array to a class. I've never done anything with OOP until last week, and now this week I'm trying to do arrays, inheritance, and polymorphism, and I'm having a hard time with it.

>>I'm wondering how to correctly link an array to a class.
Well, you can link an array to a class, but that's probably not what you want. What you want is to store an array in a class. This can be done like this:

class MyClass {
  int values[10]; //this will store ten integer values in an array inside an object of class MyClass. 
};

Of course, the array can be in either private, public or protected scope. Basically, in a class, you can store any variable that you could store as a local or global variable, and are declared the same way.

Your problem also says that you should use polymorphism. This means that the array of Guess that you would store in GuessingGame would have to be an array of pointers to Guess objects. The reason why you need to store pointers is because the objects in the array are not really Guess objects, but objects of a class derived from Guess. So this would be more appropriate:

class GuessingGame {
  public:
    static const unsigned int max_number_of_guesses;
  private:
    Guess* guesses[max_number_of_guesses];
  public:
    GuessingGame() {
      //you need to inilialize guesses to NULL:
      for(int i=0;i<max_number_of_guesses;++i)
        guesses[i] = NULL;
    };
    ~GuessingGame() {
      //and, you need to delete them afterwards:
      for(int i=0;i<max_number_of_guesses;++i)
        delete guesses[i];
    };
};

I've worked on this code but am still having issues completing this. If you see any fixes that I can make I would appreciate it. I'm still confused on where to store the array, and how to set it up.

#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
{
public:
	Guess();
	virtual string DisplayGuessResult();
	int guess;
};

class High : public Guess
{
public:
	High();
	virtual string DisplayGuessResult();
};

class Low : public Guess
{
public:
	Low();
	virtual string DisplayGuessResult();
};

class Correct : public Guess
{
public:
	Correct();
	virtual string DisplayGuessResult();
};


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 index;
			int numberOfGuesses;
			int MaxNumberOfGuesses;
			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";

			Guess*UserResponse[numberOfGuesses];

			for(index = 0; index < MaxNumberOfGuesses; index++)
			{

				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)
				{
					UserResponse[index] = new High();
					UserResponse[index] -> guess = userGuess;

					cout << "Your guess of " << userGuess << " is too high, guess lower" << endl << endl;
					continue;
				}

				if(userGuess < newGame.m_variable)
				{
					UserResponse[index] = new Low();
					UserResponse[index] -> guess = userGuess;

					cout << "Your guess of " << userGuess << " is too low, guess higher" << endl << endl;
					continue;
				}

				if(userGuess = newGame.m_variable)
				{
					UserResponse[index] = new Correct();
					UserResponse[index] -> guess = userGuess;

					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;
					}

				}

			}

			for(index1 = 0; index1 < MaxNumberOfGuesses; index1++)
			{
				UserResponse[index1] -> DisplayGuessResult();
			}

		}
}
	string yourName;
		cout << "Please type your first name and press enter. " ; // output
		cin >> yourName; // Input - User to enter in their first name
			
		return 0;
}

I'm having two issues that I know of. The one line of code I have:

Guess*UserResponse[numberOfGuesses];

I'm getting compile errors saying "error C2057: expected constant espression"
"error C2466: cannot allocate an array of constant size 0"
"error C2133: 'UserResponse' : unknown size"

Also, I'm getting another error if I hit yes to continue to run telling me that the exe file is missing in my Debug file.

The lines 84, 86, and 87 should disappear. guessArray is not really used and its use is corrupt. numberofGuess is the same as MaxNumberOfGuesses, just keep one.

The error you are getting is caused by the fact that "numberOfGuess" is not initialized to any value (defaulted, in debug mode, to 0). What value did you think it had? It is not because you name the variable MaxNumberOfGuesses that the compiler will give it a good value. In any case, to declare a static array, such as UserResponse, you need a constant value, so a variable is not correct either. So, say you want maximum 10 guesses, then, at line 85 and 93, it would be:

const int MaxNumberOfGuesses = 10; //notice the 'const' here
//..
Guess* UserResponse[MaxNumberOfGuesses]; //now this array has non-zero, constant size.

It seems that with the above changes, it should compile and run.

I made those changes as you suggested, but it still doesn't compile. These are the errors I'm getting still:

error LNK2019: unresolved external symbol "public: __thiscall Correct::Correct(void)" (??0Correct@@QAE@XZ) referenced in function _main

error LNK2019: unresolved external symbol "public: __thiscall Low::Low(void)" (??0Low@@QAE@XZ) referenced in function _main

error LNK2019: unresolved external symbol "public: __thiscall High::High(void)" (??0High@@QAE@XZ) referenced in function _main

fatal error LNK1120: 3 unresolved externals

Here is my code now, with the changes:

#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
{
public:
	Guess();
	virtual string DisplayGuessResult();
	int guess;
};

class High : public Guess
{
public:
	High();
	virtual string DisplayGuessResult();
};

class Low : public Guess
{
public:
	Low();
	virtual string DisplayGuessResult();
};

class Correct : public Guess
{
public:
	Correct();
	virtual string DisplayGuessResult();
};


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 index = 10;
			int index1;
			const int MaxNumberOfGuesses = 10;

			cout << "Please enter your guess between 1 and 100: " ; // output
			cin >> userGuess;  // Input - User to enter a guess between 1 and 100
			cout << "\n";

			Guess* UserResponse[MaxNumberOfGuesses];

			for(index = 0; index < MaxNumberOfGuesses; index++)
			{

				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)
				{
					UserResponse[index] = new High();
					UserResponse[index] -> guess = userGuess;

					cout << "Your guess of " << userGuess << " is too high, guess lower" << endl << endl;
					continue;
				}

				if(userGuess < newGame.m_variable)
				{
					UserResponse[index] = new Low();
					UserResponse[index] -> guess = userGuess;

					cout << "Your guess of " << userGuess << " is too low, guess higher" << endl << endl;
					continue;
				}

				if(userGuess = newGame.m_variable)
				{
					UserResponse[index] = new Correct();
					UserResponse[index] -> guess = userGuess;

					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;
					}

				}

			}

			for(index1 = 0; index1 < MaxNumberOfGuesses; index1++)
			{
				UserResponse[index1] -> DisplayGuessResult();
			}

		}
}
	string yourName;
		cout << "Please type your first name and press enter. " ; // output
		cin >> yourName; // Input - User to enter in their first name
			
		return 0;
}

I've done research on the errors I'm getting, but can't seem to get to the bottom of it.

error LNK2019: unresolved external symbol "public: __thiscall Correct::Correct(void)" (??0Correct@@QAE@XZ) referenced in function _main

error LNK2019: unresolved external symbol "public: __thiscall Low::Low(void)" (??0Low@@QAE@XZ) referenced in function _main

error LNK2019: unresolved external symbol "public: __thiscall High::High(void)" (??0High@@QAE@XZ) referenced in function _main

fatal error LNK1120: 3 unresolved externals

You need an implementation for the functions in all those classes:

class Guess
{
public:
	Guess();
	virtual string DisplayGuessResult();
	int guess;
};

class High : public Guess
{
public:
	High();
	virtual string DisplayGuessResult();
};

class Low : public Guess
{
public:
	Low();
	virtual string DisplayGuessResult();
};

class Correct : public Guess
{
public:
	Correct();
	virtual string DisplayGuessResult();
};

Those with the same name as the class' name is the constructor. The compiler is looking for those functions and can't find them, and thus, throws a "unresolved external symbol" (which translates to "I can't find the implementation of those functions!"). To implement them, you can do, either inside the class declaration:

class Guess
{
public:
	int guess;
	Guess() {
          guess = 0;
        };
	virtual string DisplayGuessResult() {
          cout << "The unclassified guess was " << guess << endl;
          return "whatever?";
        };
};

Or outside the declaration, as follows:

class Guess
{
public:
	int guess;
	Guess();
	virtual string DisplayGuessResult();
};

Guess::Guess() {
  guess = 0;
};

string Guess::DisplayGuessResult() {
  cout << "The unclassified guess was " << guess << endl;
  return "whatever?";
};

I just assumed that you did implement those functions, and that you just didn't post that part of the code. You need to implement them!

Mike, you are a life saver. I'm so close now. Now I'm getting these errors:

(48): error C2065: 'userGuess' : undeclared identifier
(58): error C2065: 'userGuess' : undeclared identifier
(68): error C2065: 'userGuess' : undeclared identifier
(77): error C2065: 'playAgain' : undeclared identifier
(83): error C2065: 'playAgain' : undeclared identifier

They seemed like simple fixes, I know I need to declare them some how in one of the classes. I figured userGuess should be in Guess, and playAgain should be in Correct. I tried to implement them that way, but got more fatal errors, so I took them out.

Here is my current code:

#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
{
public:
	Guess()
	{
	}
	virtual string DisplayGuessResult();
	int guess;
};

class High : public Guess
{
public:
	High()
	{
		cout << "Your guess of " << userGuess << " is too high, guess lower" << endl << endl;
	}
	virtual string DisplayGuessResult();
};

class Low : public Guess
{
public:
	Low()
	{
		cout << "Your guess of " << userGuess << " is too low, guess higher" << endl << endl;
	}
	virtual string DisplayGuessResult();
};

class Correct : public Guess
{
public:
	Correct()
	{
		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;
			}
			
			else(again = 'y');
			{
				playAgain = true;
			}
	}
	virtual string DisplayGuessResult();
};


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 index = 10;
			int index1;
			const int MaxNumberOfGuesses = 10;

			cout << "Please enter your guess between 1 and 100: " ; // output
			cin >> userGuess;  // Input - User to enter a guess between 1 and 100
			cout << "\n";

			Guess* UserResponse[MaxNumberOfGuesses];

			for(index = 0; index < MaxNumberOfGuesses; index++)
			{

				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)
				{
					UserResponse[index] = new High();
					UserResponse[index] -> guess = userGuess;

					
				}

				if(userGuess < newGame.m_variable)
				{
					UserResponse[index] = new Low();
					UserResponse[index] -> guess = userGuess;

					
				}

				if(userGuess = newGame.m_variable)
				{
					UserResponse[index] = new Correct();
					UserResponse[index] -> guess = userGuess;

					

				}

			}

			for(index1 = 0; index1 < MaxNumberOfGuesses; index1++)
			{
				UserResponse[index1] -> DisplayGuessResult();
			}

		}
}
	string yourName;
		cout << "Please type your first name and press enter. " ; // output
		cin >> yourName; // Input - User to enter in their first name
			
		return 0;
}

First, a few random things:

Line 81: it should be a double equal sign ( == ) in the if-statement.

Line 109 and 121: One of those two loops has to go, they are redundant (one loops until the right answer, the other loops for MaxNumberOfGuesses number of times). I think you ought to have ONE loop on BOTH conditions (i.e. loop while still not the right answer AND the number of guesses haven't exceeded MaxNumberOfGuesses).

Now, for where the variables should be. You have to think of this as splitting responsibility between parts of the program. Each class is a part that does something (accomplishes a contract) for the application (and the main() function should merely be "launching" the objects into action, so a typical OOP program will have very few lines of code in the main() function).

Here, you have two very distinct contracts:
GuessingGame: Should execute the game and store all the data necessary for that.
Guess: Should keep a record of one guess that was taken.
Plus three sub-contracts:
High: Should qualify a guess as too high.
Low: Should qualify a guess as too low.
Correct: Should qualify a guess as correct.

By the above contracts, you can split the data (and their use) between classes very easily by asking which purpose they serve. Obviously, the playAgain variable should be in GuessingGame because its purpose is to determine whether the game should continue (and GuessingGame is responsible for executing the game). As for userGuess, it is a temporary variable used in the execution of the game, so it should be part of the execution of the game (duh!), which, in turn, should be part of the GuessingGame class. Basically, you should move the entire program into a function of GuessingGame (something like execute() or play()) and your main function should just create the newGame and call execute() on it.

As for the errors you are getting, it is because of the mix-up of responsibilities. The playAgain variable is part of the execution of the game, not of a record of a guess (which is what Guess and Correct classes are for). So the part that sets the value of playAgain should not be part of the Correct class (i.e. lines 70 to 84 should be moved out of there, logically, to where line 150 is now).

As for userGuess, you can pass this variable as a parameter to the constructor, as so:

class Guess
{
public:
	Guess(int userGuess)
	{
          guess = userGuess; //this sets the guess record to the passed parameter.
	}
	virtual string DisplayGuessResult();
	int guess;
};

class High : public Guess
{
public:
	High(int userGuess) : Guess(userGuess) //here, this calls the base-class constructor with "userGuess" as parameter.
	{
		cout << "Your guess of " << guess << " is too high, guess lower" << endl << endl;
	}
	virtual string DisplayGuessResult();
};

//And similarly for Low and Correct.

And to call the constructor with the parameters, you need to simply pass the parameter. So, on line 132, 140, and 148, you do something similar to this:

UserResponse[index] = new High(userGuess); //initialize High object with userGuess.

I moved the initialization lines of userGuess and playAgain outside of the main function to just below the using namespace line, and this seemed to fix this problem, but now I have new problems.

Now I am getting 4 new fatal errors of type LNK1120. They are unresolved external errors, one for High, Low, Correct, and Guess. They say the following:

error LNK2001: unresolved external symbol "public: virtual class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall High:: DisplayGuessResult(void)" (?DisplayGuessResult@High@@UAE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ)

It shows the same error for the other three items, just switch out the class name.

Edited 5 Years Ago by Szeth: n/a

I did the stuff in that last post prior to reading this post...working on understanding what you wrote here.

Ok, so here is my issue now. I made the adjustments that you suggested, and the program compiles without error now. It doesnt work correctly though. When I guess a number it says whether the guess is high or low, but then it immediately prints that my guess of # is correct. The next issue is when i tell it yes to playing again, it says my guess of # is correct, for the new game. Here is my code, i entered "blah blah" in the part after the DisplayGuessResults() :

#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.
int userGuess = 0; // users guess of the random number
bool playAgain=true;  // Boolean expression used to offer the ability to play the game again.

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
{
public:
	Guess()
	{
	}
	virtual void DisplayGuessResult()
	{
	cout << "blah blah" << endl;
	}
	int guess;
};

class High : public Guess
{
public:
	High()
	{
		cout << "Your guess of " << userGuess << " is too high, guess lower" << endl << endl;
	}
	virtual void DisplayGuessResult()
	{
	cout << "blah blah" << endl;
	}

};

class Low : public Guess
{
public:
	Low()
	{
		cout << "Your guess of " << userGuess << " is too low, guess higher" << endl << endl;
	}
	virtual void DisplayGuessResult()
	{
	cout << "blah blah" << endl;
	}
};

class Correct : public Guess
{
public:
	Correct()
	{
		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;
			}
			
			else(again == 'y');
			{
				playAgain = true;
			}
	}
	virtual void DisplayGuessResult()
	{
	cout << "blah blah" << endl;
	}
};


int main ()
{
	
		
				
		// 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();
		

		
		while(playAgain)
		{
			newGame.regenerate();

		while (userGuess != newGame.m_variable)  // Loops forever, or until user finds the number.
		{
			int index = 10;
			int index1;
			const int MaxNumberOfGuesses = 10;

			cout << "Please enter your guess between 1 and 100: " ; // output
			cin >> userGuess;  // Input - User to enter a guess between 1 and 100
			cout << "\n";

			Guess* UserResponse[MaxNumberOfGuesses];

			for(index = 0; index < MaxNumberOfGuesses; index++)
			{

				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)
				{
					UserResponse[index] = new High();
					UserResponse[index] -> guess = userGuess;

					
				}

				if(userGuess < newGame.m_variable)
				{
					UserResponse[index] = new Low();
					UserResponse[index] -> guess = userGuess;

					
				}

				if(userGuess = newGame.m_variable)
				{
					UserResponse[index] = new Correct();
					UserResponse[index] -> guess = userGuess;

					

				}

			}

			for(index1 = 0; index1 < MaxNumberOfGuesses; index1++)
			{
				UserResponse[index1] -> DisplayGuessResult();
			}

		}
}
	string yourName;
		cout << "Please type your first name and press enter. " ; // output
		cin >> yourName; // Input - User to enter in their first name
			
		return 0;
}

Made a couple more changes, still having issues, but getting closer. Got rid of the duplicate 'for' loop :

#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.
int userGuess = 0; // users guess of the random number
bool playAgain=true;  // Boolean expression used to offer the ability to play the game again.

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
{
public:
	Guess()
	{
	}
	virtual void DisplayGuessResult()
	{
	cout << "blah blah" << endl;
	}
	int guess;
};

class High : public Guess
{
public:
	High()
	{
		cout << "Your guess of " << userGuess << " is too high, guess lower" << endl << endl;
	}
	virtual void DisplayGuessResult()
	{
	cout << "blah blah" << endl;
	}

};

class Low : public Guess
{
public:
	Low()
	{
		cout << "Your guess of " << userGuess << " is too low, guess higher" << endl << endl;
	}
	virtual void DisplayGuessResult()
	{
	cout << "blah blah" << endl;
	}
};

class Correct : public Guess
{
public:
	Correct()
	{
		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;
			}
			
			else(again == 'y');
			{
				playAgain = true;
			}
	}
	virtual void DisplayGuessResult()
	{
	cout << "blah blah" << endl;
	}
};


int main ()
{
	
		
				
		// 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();
		

		
		while(playAgain)
		{
			newGame.regenerate();

		while (userGuess != newGame.m_variable)  // Loops forever, or until user finds the number.
		{
			int index = 10;
			int index1;
			const int MaxNumberOfGuesses = 10;

			cout << "Please enter your guess between 1 and 100: " ; // output
			cin >> userGuess;  // Input - User to enter a guess between 1 and 100
			cout << "\n";

			Guess* UserResponse[MaxNumberOfGuesses];

			for(index = 0; index < MaxNumberOfGuesses; index++)
			{

				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)
				{
					UserResponse[1] = new High();
					UserResponse[1] -> guess = userGuess;

					
				}

				if(userGuess < newGame.m_variable)
				{
					UserResponse[1] = new Low();
					UserResponse[1] -> guess = userGuess;

					
				}

				if(userGuess == newGame.m_variable)
				{
					UserResponse[1] = new Correct();
					UserResponse[1] -> guess = userGuess;

					

				}

			}

			
				UserResponse[1] -> DisplayGuessResult();
			

		}
}
	string yourName;
		cout << "Please type your first name and press enter. " ; // output
		cin >> yourName; // Input - User to enter in their first name
			
		return 0;
}

>>I made the adjustments that you suggested
No, you didn't. You almost did the exact opposite:
1) you didn't merge the two redundant loops (and this is what is causing the weird execution you are seeing)
2) you made userGuess and playAgain global variables instead of data members (in terms of order of preference: data members are best, local variables are also very good, static data members are OK, global variables are EVIL!)
3) you kept most of the code in the main function where it doesn't belong.
4) you didn't split the responsibility correctly as I suggested.

I think you have suffered enough working on this problem. Let me just show you what you would have obtained if you followed the guidelines of my previous post:

#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 Guess
{
  public:
    int guess;
    Guess(int userGuess) : guess(userGuess) { };
    virtual void DisplayGuessResult() = 0;
};

class High : public Guess
{
  public:
    High(int userGuess) : Guess(userGuess) { };
    virtual void DisplayGuessResult()
    {
      cout << "Your guess of " << guess << " is too high, guess lower" << endl << endl;
    };
};

class Low : public Guess
{
  public:
    Low(int userGuess) : Guess(userGuess) { };
    virtual void DisplayGuessResult()
    {
      cout << "Your guess of " << guess << " is too low, guess higher" << endl << endl;
    };
};

class Correct : public Guess
{
  public:
    Correct(int userGuess) : Guess(userGuess) { };

    virtual void DisplayGuessResult()
    {
      cout << "Congratulations, you are CORRECT with your guess of " << guess << " !" << endl << endl;
    };
};

class GuessingGame 
{
  public:

    GuessingGame(int seed)
    {
      srand(seed);
      regenerate();
    };
	
    int storedRandomNumber() {
      return m_variable;	
    };

    void regenerate() {
      m_variable = rand() % (maxRandomNumber - minRandomNumber + 1) + minRandomNumber;
    };
    static const int maxRandomNumber = 100;
    static const int minRandomNumber = 1;
    static const int MaxNumberOfGuesses = 10;
    int m_variable;

    void execute() {
      bool playAgain = true;
      while(playAgain)
      {
        regenerate();

        int index = 0; //index of the current guess being taken.
        Guess* UserResponse[MaxNumberOfGuesses]; //record of all guesses so far.

        while(index < MaxNumberOfGuesses) { // Loops for a fixed number of guesses (or a breaking condition).
          int userGuess = 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 > maxRandomNumber || userGuess < minRandomNumber) {
            cout << "Please stay within the parameters of guesses between 1 and 100!" << endl;
            continue;
          };

          if(userGuess > m_variable)
            UserResponse[index] = new High(userGuess);
          else if(userGuess < m_variable)
            UserResponse[index] = new Low(userGuess);
          else if(userGuess == m_variable)
            UserResponse[index] = new Correct(userGuess);

          UserResponse[index]->DisplayGuessResult();

          ++index;

          if(userGuess == m_variable)
            break;
        };

        //it is important to delete anything that you allocate with "new":
        for(int i=0;i<index;++i)
          delete UserResponse[i];

        //at this point, the game is finished (one way or another) and ask to play again:
        char again;
        cout << "Do you want to play again?  Enter y for yes or n for no: " ;
        cin >> again;
        cout << endl;

        if(again != 'y') {
          playAgain = false;
          cout << endl << "Thank you for playing My Number Generator Game! " << endl << endl;
        };
      };
    };
};


int main ()
{
  // 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.execute();

  string yourName;
  cout << "Please type your first name and press enter. " ; // output
  cin >> yourName; // Input - User to enter in their first name
		
  return 0;
}

You can observe from the above how easy it becomes when you assign clear responsibility to each piece of the software (i.e. DisplayGuessResult only displays the result of the guess, the Guess constructor only constructs a Guess object (nothing else), the GuessingGame handles everything about executing the game, etc.). The result is that you get no EVIL global variables, no problems with trying to access data that you shouldn't, etc. etc. it all just falls more easily into place. You can also see that all I really did is change the structure and it fixed the problem, I didn't "add" any significant piece of code (except for the delete loop and some bits of cleaning up the format). The lesson is: if you structure you code correctly, it all becomes a lot simpler to write, understand, and debug.

Mike, you are the bomb. Did you ever try being a college instructor? The one I currently have is not much help. He has us read a book online, then tells us to do stuff without any direction.

>>Did you ever try being a college instructor?
Yes I did and their's a good chance I will do more of it in the future.

>>He has us read a book online, then tells us to do stuff without any direction.
Sounds like you might want to file a complaint, or at least voice some concerns in the feedback channels that I assume your college has (course/teacher reviews or feedback surveys). Remember that as a college student, you are, in some sense, a paying customer, you have to right to complain if the teachers isn't good. I did see a clear mismatch between the amount you were asked to do and the amount you seemed to have learned prior to starting to work on the problem.

Yea, the crazy thing is now I need to update the program again to use exception handling and a few other things.

This article has been dead for over six months. Start a new discussion instead.