Have a text file with 2 columns. Load the columns into a map . Pick a random word from the map by using a function like srand() (keeping in mind that the number must be below the .size() of the map. if the answer they provide equals the value in the map for that key, they get it right.
Another way is to have a word list file like above, except only with the correctly spelled words. Then you read a word, copy it, do a random shuffle, and use those two strings. That way the jumble will be more likely to change often without the tediousness of editing the file.
Better yet, you can also read the file into a vector and do a random shuffle on it as well as the words so that people who play the game often will have a harder time finding patterns and remembering the word order to win more easily. :)
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
There is more than one way to do most tasks. You can probably accomplish this task by using index values and an an array of strings. Develop a 2d array of strings to represent each word available. The first column could represent the scrambled word and the second the correct word. Call srand once in the project. call rand % numberOfStringInTheArray to get a ranom int to represent the row of the table to use. Use array[index][0] to get the scrambled word and array[index][1] to get the correct version.
Lerner
Nearly a Posting Maven
2,382 posts since Jul 2005
Reputation Points: 739
Solved Threads: 396