Hey
I'm doing a hangman project at the moment,I have a string array containing 10 words to be guessed.I can generate a random number between 0 and 9 but how do i compare this to the index of the elements to randomly pick a word???
thanks
This is a discussion on pick randomly from array within the C++ Programming forums, part of the General Programming Boards category; Hey I'm doing a hangman project at the moment,I have a string array containing 10 words to be guessed.I can ...
Hey
I'm doing a hangman project at the moment,I have a string array containing 10 words to be guessed.I can generate a random number between 0 and 9 but how do i compare this to the index of the elements to randomly pick a word???
thanks
Since you can pick a random number in the right range, just use THAT as the index into the array.
Mac and Windows cross platform programmer. Ruby lover.
Quote of the Day
12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.
Amen brother!
I am not sure what is the question. Don't you already have a random index that you can immediately use?
C + C++ Compiler: MinGW port of GCC
Version Control System: Bazaar
Look up a C++ Reference and learn How To Ask Questions The Smart Way
Ok,i have an array with 10 words and i want to pick one of them randomly,how do i do it
You would "generate a random number between 0 and 9" and then use that number as the index of the randomly chosen element.
C + C++ Compiler: MinGW port of GCC
Version Control System: Bazaar
Look up a C++ Reference and learn How To Ask Questions The Smart Way