A simple IOstream game not compiling

Help!!!

Here what I want to do: a simple game where a player is given the choice of
two buttons to click, if he clicks them in the correct order he wins. the current correct combination is (right, left, right)

If he does not find the right order, the game continues until he does.

I get the error "Expression must be a modifiable lvalue" and it fails to compile.



1
2
3
4
5
6
7
8
9
10
11
12
13
14
for (;;){
int game1[3]; 

 for (int i=0; i<3; i++){
cout<< "you see two buttons, what do you click on?" ; 
cout<< "    1.Click on right one \n";
cout<< "    2.Click on left one  \n";
  cin>> game1[i];
 }

 if ( game1[0] ==1 && game1[1] == 2 && game1[2] = 1) {
	 break;
 }
}

Typo at line
if ( game1[0] ==1 && game1[1] == 2 && game1[2] = 1) {


game1[2] = 1 is assignment
game1[2] == 1 is checking the value

(Most experienced programmers also make this common mistake of using = instead of ==. Better to make habit of using
<constant value> == <variable name>
instead of
<variable name> == <constant value>.
This way we can catch errors during compile time. )
Last edited on
Topic archived. No new replies allowed.