I have a 2 player hangman game for class which outputs to the windows command prompt. I use the random number function to select a word from a file and i want to have player two's word be the same length as player one's. After compiling i have no errors but upon execution only the cursor displays. Any help would be appreciated.
One way might be to first generate a random word length.
Then load all the words of that length into a vector.
Then select two words at random from that vector?
That way you will know exactly how many words you have before selecting the random number needed to choose one. So you can select a random number that will definitely be lower than or equal to the number of available words of a given length.
Still displays only the cursor, if i comment out the while and if statements it works but the problem is the words are of different lengths. I'll have to try the vector idea or maybe use arrays.
Still displays only the cursor, if i comment out the while and if statements it works but the problem is the words are of different lengths. I'll have to try the vector idea or maybe use arrays.
I think the problem is that by the time you come to select the second word you are already half way through the file. Given that you have no idea how many words of a given length are going to be in the file it makes sense to read all the words of the given length in first. Then when you know how many of them that there are word_list.size(); you can easily select two from the list at random.