How do I make this so it wont guess the same number more than once? In reality, it should only have to guess a maximum times of 100 because the numbers range from 1-100. When I run the program it can take it 500 times to get the right answer.
I want to eliminate the possibility of it guessing the same number twice
In reality, it should only have to guess a maximum times of 100 because the numbers range from 1-100
Not necessarilly, it`s a random process, you could get 10 times each number till you get the result, and it would sum up to 1000 trials!!
Nevertheless, if you want to do it anyway, I think you could save each guess in a vector of 100 elements and check this vector each time to see if the number is already there. But it would be like cheating, because you need a trial to check, no matter you count it or not...
You are going to need some way to keep track of the guessed numbers. What I would do though is just create an array of the 100 numbers then randomly sort it and iterate through it till it finds the correct value.
1 2 3 4 5 6
std::vector<int> guesses(100);
std::generate(guesses.begin(), guesses.end(), [&](){staticint count = 1; return count++;});
std::random_shuffle(guesses.begin(), guesses.end());
//now just iterate over guesses till you found the correct answer.
well...technically it's not random it's just following a pattern. I think what he wants is to pick a unique pseudo random number each time from a list of numbers. Not an arbitrary pseudo random each time.