Hello C++ Guru's. I have a little bit of a problem with a bit of come.
I'm making a little "game" where you guess on a number 1-50 and if you guess the right on in less than 10 tires you can play Double or Nothing. All your guesses needs to be stored into an array, and then in Double or Nothing it has to print out 5 of the numbers you guessed on.
I need to get the players choice of number into an array, and the player is able to make as many guesses as possible to the array might become huge.
1 2
cout << "Make your guess now! : ";
cin >> guess;
That's how it looks when the player guesses, so I need to get the input from "guess" into an array, whose size increases with every guess.
in c++ you can use std::vector<int> to store the input.
1 2 3 4 5 6 7 8 9
std::vector<int> playerOptions;
while (playerOptions.size() < 10) // maximum 10 guesses
{
std::cout << "Make your guess now! : ";
int guess;
std::cin >> guess;
if (...) break; // if guess matches the input, break the loop
playerOptions.push_back(guess); // save the wrong guess
}
And then you could use saved wrong guesses in playerOptions
std::cout << playerOptions[0] << std::endl; // or something else