# Thread: Tic tac toe win

1. ## Tic tac toe win

Why doesn't this work for checking a win?

Code:
```//Check xWin
bool xwin(string l1,string l2,string l3)
{
if (l1=="xxx")
return true;
if (l3=="xxx")
return true;
if (l2=="xxx")
return true;
if (l1[1]=="x" && l2[1]=="x" && l3[1]=="x")
return true;
if (l1[0]=="x" && l2[1]=="x" && l3[2]=="x")
return true;
if (l1[0]=="x" && l2[0]=="x" && l3[0]=="x")
return true;
if (l1[2]=="x" && l2[1]=="x" && l3[0]=="x")
return true;
if (l1[2]=="x" && l2[2]=="x" && l3[2]=="x")
return true;
else
return false;
}```
sorry if im getting annoying but this is due tomorrow at midnight and i have no idea what im doing

2. Code:
```if (l1[2]=="x" && l2[2]=="x" && l3[2]=="x")
return true;
else
return false;```
When does that return false?

Also, what type is l1[2]?

3. it will be repeated after each turn... i will have a separate one for o's and if spaces occupy the winning spots, it will return false. right?

4. it will be repeated after each turn
That's not what I meant, but it should be ok. Your code doesn't even compile, so how could it work? Check the late edit I made to my previous post.

5. I know it doesn't compile, sir. I get something like "ISO C++ cannot allow comparisons between a pointer and an int." I have no clue what a pointer is, so I have no clue where to start.

6. Ok. But, when you post a question and your program doesn't compile, you should list the exact error message and add a comment on the line in your code where the error occured.

However, for now concentrate on something else: what type is l1[2]?

7. part of a string

8. What are the individual things that make up a string called?

"part of a string" is not a C++ type.

9. char

10. Correct! Now, post a line of code that declares a char variable and assigns it a letter.

11. Code:
`char stud7='x';`

12. lol. Ok, so you know that l1[2] is a char type and a char looks like this: 'x'. Now, look at your if statements. What are you comparing l1[2] to?

13. ah thank you