Puzzle R14

Generate words of five random characters until the word "hello" occurs

[M-15] Write a main() program that generates 5-character random words until the word "hello" is generated. Use the randWord() function from B12. So that the user can see that the program is working, print out one dot for every 100,000 words generated. Typical output is:

..................................................
..................................................
..................................................
..............
word = hello, count = 16479997

A randomly generated "hello" should happen once per every 26*26*26*26*26 words generated, about once per 11,881,376 random words.

Use the function int strcmp( char*, char* ) to compare a randomly generated word with "hello". That function returns 0 when the two strings are equal.

Of course, if you use char randCharFreq() from a previous puzzle "hello" should occur more often.



Previous Page        Answer         Next Page         Home