Randomize (please help

This is a discussion on Randomize (please help within the C++ Programming forums, part of the General Programming Boards category; Hi guys
I am new to programming and need help. I need to create a quiz using random in C++. ...

Randomize (please help

Hi guys

I am new to programming and need help. I need to create a quiz using random in C++. I have 2 arrays of the same words in the same order in 2 languages. I would like to write a piece of code that picks a word at random from one of the arrays and askes for the equivelent word from the other array. I would need a loop of some kind to give the user so many attemps. What header file do I need to use for random? Any help would be great.

When you says two arrays of words, are you talking about a string of words separated by spaces like

Code:

EnglishWord1 EnglishWord2 EnglishWord3

or something similar? If so, I would rethink your design. It'd be much easier to have an array of char pointers and set those equal to string constants (or the addresses of other strings if the strings are supplied by file or other method at run time).

When you says two arrays of words, are you talking about a string of words separated by spaces like

Code:

EnglishWord1 EnglishWord2 EnglishWord3

or something similar? If so, I would rethink your design. It'd be much easier to have an array of char pointers and set those equal to string constants (or the addresses of other strings if the strings are supplied by file or other method at run time).

If your array has 50 entries, simply use the links posted above for how to get a random number between 0 and 49 (inclusive). That will randomly pick an english word from your array.

To ask for a translation might be more difficult, since you would have to search your Tagalog array for the string the user enters. One easier option is to list all the words in the tagalog array with a number (like 1 - 50: the array index + 1) and have the user pick the number of the matching word. If the number they pick matches the random number + 1, it is correct. The +1 is because array offsets start at 0 but users usually will think starting from 1.

The setup of the map could be made easier if the English/Tagalog words were read in from a file. Then you wouldn't need some huge set of insert statements, you'd just have a loop that reads through a file. You should be able to take the above a modify it to print out the English word stored in the map, ask the user for the translation, and then compare what the user entered with the translation that is also stored in the map.

"Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
-Christopher Hitchens