Quote:
Originally Posted by ilikepython
Do you have a string array of 10 words? If yes, then you can have the index be the random number.
-
void sethiddenword(){ // no need to pass an array
-
int rnum;
-
srand(time(0));
-
rnum = rand() %10;
-
string hidden = wordlist[rnum]; //you can do it with strings
-
return hidden;
-
or
-
char hidden[] = wordlist[rnum]; // or with char arrays
-
return hidden;
-
}
-
That's what I did when I made my hangman. Also, you might want to change the function from a void to string return or a char array so you can return the word to main. I recommend using strings if you are using C++ but you can also do it with char arrays.
I have to do it in just C i cant do it in C++ so i guess i have to use char arrays. I do not know what a word list is, but i have 10 words on paper that i can use, like "computer", and "hello", i do not know how to bring them into th program without doing something like.
char wordone[size] = "word"; 10 times.