Memmory game problem

Hello, i'm new to these forums. I started c++ a week ago but it looks fun!
Anyways, I'm making this little memmory game. Now, the point of this game is to type 10 words. After that you will have to type them again to see if you remembered them correctly. But it says you allways loose.
Here's the code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#include <iostream>
#include <cmath>
#include <fstream>
#include <cstdlib>
#include <windows.h>
using namespace std;

int main(){

cout << "Game!" << endl;
char startan[20];
cout << "To start type play. To exit type leave." << endl;
cin >> startan;
//Checking the first answer.
if(strcmpi(startan, "start")==0){
cout << "Alright let's start!" << endl;
char firstw[20];
char secondw[20];
char thirdw[20];
char fourthw[20];
char fifthw[20];
char sixthw[20];
char seventhw[20];
char eigthw[20];
char ninthw[20];
char tenthw[20];
/*------------------------*/
cout << "You will enter ten words, and then you will have to re-enter them in order to prove your memmory skills!" << endl;
system("pause");
system("cls");
cout << "Input your first word: ";
cin >> firstw;
cout << endl;
system("cls");
cout << "Input your second word: ";
cin >> secondw;
cout << endl;
system("cls");
cout << "Input your third word: ";
cin >> thirdw;
cout << endl;
system("cls");
cout << "Input your fourth word: ";
cin >> fourthw;
cout << endl;
system("cls");
cout << "Input your fifth word: ";
cin >> fifthw;
cout << endl;
system("cls");
cout << "Input your sixth word: ";
cin >> sixthw;
cout << endl;
system("cls");
cout << "Input your seventh word: ";
cin >> seventhw;
cout << endl;
system("cls");
cout << "Input your eighth word: ";
cin >> eigthw;
cout << endl;
system("cls");
cout << "Input your ninth word: ";
cin >> ninthw;
cout << endl;
system("cls");
cout << "Input your tenth word: ";
cin >> tenthw;
cout << endl;
system("cls");
char firstwo[20];
char secondwo[20];
char thirdwo[20];
char fourthwo[20];
char fifthwo[20];
char sixthwo[20];
char seventhwo[20];
char eigthwo[20];
char ninthwo[20];
char tenthwo[20];
cout << "Alright. Now type in those words again, and i'll see if they match! :D" << endl;
system("pause");
system("cls");
cout << "Input your first word again: ";
cin >> firstwo;
cout << endl;
system("cls");
cout << "Input your second word again: ";
cin >> secondwo;
cout << endl;
system("cls");
cout << "Input your third word again: ";
cin >> thirdwo;
cout << endl;
system("cls");
cout << "Input your fourth word again: ";
cin >> fourthwo;
cout << endl;
system("cls");
cout << "Input your fifth word again: ";
cin >> fifthwo;
cout << endl;
system("cls");
cout << "Input your sixth word again: ";
cin >> sixthwo;
cout << endl;
system("cls");
cout << "Input your seventh word again: ";
cin >> seventhwo;
cout << endl;
system("cls");
cout << "Input your eighth word again: ";
cin >> eigthwo;
cout << endl;
system("cls");
cout << "Input your ninth word again: ";
cin >> ninthwo;
cout << endl;
system("cls");
cout << "Input your tenth word again: ";
cin >> tenthwo;
cout << endl;
system("cls");

if(firstwo == firstw || secondwo == secondw || thirdwo == thirdw || fourthwo == fourthw || fifthwo == fifthw || sixthwo == sixthw || seventhwo == seventhw || eigthwo == eigthw || ninthwo == ninthw || tenthwo == tenthw){
cout << "Congratulations!! You win!! :D" << endl;

}
else{
cout << "You loose. Try again." << endl;
}
}
else if(strcmpi(startan, "leave")==0){
cout << "Exiting the game. Hope you had fun! :D" << endl;
exit(EXIT_FAILURE);
}
else{
cout << "Type either play or leave. \n So do you want to play or do you want to leave?" << endl;
cin >> startan;
}

cin.get();
cin.get();
return 0;
}

Any help would be apprecciated, please respond with simple terms, as i am new.
This is a mess so I'm just gonna clean it a bit.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <cstdlib>
#include <iostream>
using namespace std;
int main(){
  char a[10][20], b[10][20];  //since you want arrays, made them 2-dimensional
  for(int i=0; i<10; ++i)
    for(int j=0; j<20j ++j){
      a[i][j]=' ';
      b[i][j]=' ';}
  for(int i=0; i<10; ++i){
    cout<<"Word No."<<i+1<<":  ";
    cin>>a[i];}
  system("CLS");
  for(int i=0; i<10; ++i){
    cout<<"Word No."<<i+1<<":  ";
    cin>>b[i];}
  system("CLS");
  bool ok=1;
  for(int i=0;i<10;i++)
    for(int j=0;j<20;j++)
      if(a[i][j]!=b[10][20]){
        ok=0;
        break;}
  if(ok)
    cout<<"You win!\n";
  else
    cout<<"You lose!\n";
  cin.sync();
  cin.get();
}

Don't have a compiler handy to check the sizes (whether or not you CAN put a 20 char word).
I suggest you try that. If the sizes are off try switching around the 10s and 20s.
You have two problems. First you can't use == to compare strings: You must use a function like strcmp().

Second, you need && (logical and) between each test, not || (logical or).

Your test should look like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

if(
    ( 0 = strcmp( firstwo, firstw ) ) &&
    ( 0 = strcmp( secondwo, secondw ) ) &&
    ( 0 = strcmp( thirdwo, thirdw ) ) &&
    ( 0 = strcmp( fourthwo, fourthw ) ) &&
    ( 0 = strcmp( fifthwo, fifthw ) ) &&
    ( 0 = strcmp( sixthwo, sixthw ) ) &&
    ( 0 = strcmp( seventhwo, seventhw ) ) &&
    ( 0 = strcmp( eigthwo, eigthw ) ) &&
    ( 0 = strcmp( ninthwo, ninthw ) ) &&
    ( 0 = strcmp( tenthwo, tenthw ) ) )
    {
    cout << "Congratulations!! You win!! :D" << endl;

    }

@ kooth:
Why use a specialized function?
You can just use a
1
2
3
4
5
bool check=1;
for(...)
  if(a[i]!=b[i]){
    check=0;
    break;}
Specialized? I'm trying to explain the program in the style of the poster's code, so as to help in his understanding.
@kooth Oh right i used the strcmpi on the top but i guess i forgot to use it in the second step. Thank you all for your help. I'll try your methods asap! And i still have ALOT to learn. For example i don't know what a 2d array is. But i will now start reading some tutorials including the one on this site. And i hope i'll get better.
Last edited on
Well, DeusExInfernus was reccomending two-dimentional arrays. You will encounter them from time to time. If you haven't gotten your copy of "The C++ Programming Language" by Stroustrup, you should have Santa bring you one! ;)
Hmm i'm not sure if we have that book here in portugal but i'll try to find it. And if we do have it, i'm tottaly going to order it! Thank you for your advice.
Topic archived. No new replies allowed.