Problem with memory program/game

Would really appreciate some help because I'm stuck and don't know what to do.

The idea is to create a memory game that can be played by 2 players.
In the beginning you choose how many number of words that will be used (max 20), all words are contained within a string.

Let's say the player chooses 5 words, I then display 5 words from the string that will be in the game and then I somehow need to (I don't know how to) duplicate those 5 words so that there are 10 words.
Ex:
How many words do you want to play with (max 20): 5
The words are: Apple, Banana, Lemon, strawberry, Olive.
and after that I need to make it so that there are 2 apples, 2 bananas, 2 lemons etc etc. aka 10 words and scramble them.

1
2
3
4
5
6
7
8
9
10
11
12
string mWords[20] = { and then 20 words in here };
int choice;
int nWords[20] = { 1, 2, 3.... 20 };

cout << "How many words do you want to play with (max 20): ";
cin >> choice; cin.ignore();
cout << endl;
cout << "These are the words: ";
for(int i = 0; i < choice; ++i)
{
cout << mWords[i] + ", ";
}

and then I scramble the words with:
1
2
3
4
5
int pos1 = rand() % nWords[choice];
int pos2 = rand() % nWords[choice];
string temp = mWords[pos1];
mWords[pos1] = mWords2[pos2]
mWords2[pos2] = temp;

and then I display the scramble words just to see that everything works as it should but it doesn't.. It should show Apple, Banana, Lemon, strawberry and Olive * 2 and scrambled but sometimes when I run the program the words never scramble and sometimes it does scramble like it should and sometimes I get 1 extra word that isnt suppose to be in there and 1 less of the current words.

What I mean with that is that when you choose for example 5 in the beginning, it takes the 5 first words in the string and then when it scrambles I sometimes get the word that has the value 6 in the string.

If this doesn't make any sense I can provide the whole code if that would help.
Thanks in advance.
closed account (48T7M4Gy)
By all means show us the whole code. If you have a look around this problem has been discussed elsewhere on this forum.
http://www.cplusplus.com/forum/beginner/175003/
Last edited on
Did not see that thread, thank you for showing it. It seems like it is the same assignement I am working on.
Thank you.
Topic archived. No new replies allowed.