Random Word Selector won't work?

I got a problem. This random selector doesn't seem to work. Only selects the word corrosponding to the number on line 3.

1
2
3
4
                srand(time(NULL));
		random = rand()%30;
		strcpy(hiddenword,words[0]);
		len = strlen(hiddenword);
Last edited on
Do you think perhaps the random number you generated on line 2 should be used somewhere? Maybe it could be used as a subscript for the array of words.
This is my array:

1
2
3
4
5
6
7
8
9
10
char words[30][15]={"bad","easy","hello",
							"hurt","dead","code",
							"hate","kill","ice",
							"fire","icecream","hangman",
							"destroy","computer","book",
							"dictionary","technology","power",
							"thunder","controller","dexterity",
							"keyboard","thunderous","blizard",
							"hazardous","algorithm","space",
							"operation","assignment","despicable"};


This is the random selector again:

1
2
3
4
srand(time(NULL));
		random = rand()%30;
		strcpy(hiddenword,words[0]);
		len = strlen(hiddenword);
strcpy(hiddenword,words[random]);
THANK YOU SO MUCH DUDE!

Could you help me with this as well?

How can I make so when count is equal to the string length of the random word the game is over?

Crap code, maybe gives you an idea:

1
2
3
4
if(count==strlen(hiddenword[0])

{
cout<<"you win";


count is an int

 
int count;


hiddenword is an array

 
char hiddenword[15]


Do you get what I am trying to say? :)

Thanks so much dude!
Last edited on
I'm not seeing the complete picture here. In the previous code, you already found the length of the random word, len = strlen(hiddenword);

So maybe you just need to test like this. But I don't know what is count, so maybe I'm wrong.
1
2
3
4
if (count == len)
{
    cout<<"you win";
}


Cheers man! You are such a helpful person. I am still at Uni with my mates atm. Do you know of a way so I can loop back to the start of the function? This final answer will mean I can go home. :)

Last edited on
Topic archived. No new replies allowed.