Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Word Jumble

Hi
In my high school c++ class we have been assigned a project to make a game in which the compiler reads a bunch of words from a file, jumbles them and show them to the screen one by one. The user have to solve the word jumble to proceed to the next word. We have to utilize structure, functions and random function.

Now I know everythin else, like ofstream to read in the words, I know how to use a function and a structure, But the problem is with the random function. How do I get the string to break down into separate characters,then randomize the characters and display to the screen.

Please keep in mind this is a high school course so I dont know much advanced c++ stuff. Thanks in advance for the help
[734 byte] By [The Master] at [2007-11-11 10:28:27]
# 1 Re: Word Jumble
there is a random shuffle algorithm in c++ that would do nicely, if you can use these built in features. If you cannot use this (not allowed or whatever) then you can pick 2 index in the word and swap them about 20 times.
jonnin at 2007-11-11 20:58:43 >
# 2 Re: Word Jumble
standard strings and char arrays both allow you to get at a single char, which are you using?
jonnin at 2007-11-11 20:59:54 >
# 3 Re: Word Jumble
Im reading the words from a notepad file and storing them in a string array. How do use the random shuffle algorithm, I think we are allowed to use that.
The Master at 2007-11-11 21:00:53 >
# 4 Re: Word Jumble
result = random.shuffle(astring);

However it is unclear if this will work on a string or if you need to get it in char array format first. I do not do a lot of string manipulation but you can get the raw array from a string if the function expects that instead. Take a look in the help and see what it has to say...
jonnin at 2007-11-11 21:01:54 >
# 5 Re: Word Jumble
Thanks for your help, I figured out another way to randomize the string, I got 60% of my project done and now onto finish the rest in 20 minutes. Again, Thanks for your help
The Master at 2007-11-11 21:02:47 >