You should definitely look into using a std::vector instead of an array of ints. You can push_back() each element so the vector will grow to accommodate the new guesses. You could also use an std::set instead of an std::vector to "automatically" tell if a number had already been guessed. If the size of the set doesn't change when you insert(), then the number was already in the set!
Let us know if you have problems trying any of this.
Good luck,
Dave
daviddoria
Posting Virtuoso
1,996 posts since Feb 2008
Reputation Points: 437
Solved Threads: 204
You seem to have the right idea, but you are defining your guess array to be an array of integers that is (0) elements long. It's not technically illegal, but it's very unsafe.
There might be a better way to do it, but I would suggest you treat it more like analyzing a distribution. Create a bool array with 101 elements (elements 0-100), then each time the user enters a legal guess, you use the guess as the array element to look at. If the element is true, the guess has been used. If the element is false, set it to true and then continue to process accordingly.
[edit]
A little slow. It looks like dave's suggestion is a better one.
Fbody
Posting Maven
2,930 posts since Oct 2009
Reputation Points: 833
Solved Threads: 393
I guess it depends on the logic of the program. You may want to use Fbody's suggestion of a bool array because say the number you guess is greater than the secret number - you'd want to mark ALL of the number above the guess as "used" because you've already effectively guessed that whole range.
daviddoria
Posting Virtuoso
1,996 posts since Feb 2008
Reputation Points: 437
Solved Threads: 204