# Tic tac toe win

• 10-30-2005
howeezy
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
• 10-30-2005
7stud
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]?
• 10-30-2005
howeezy
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?
• 10-30-2005
7stud
Quote:

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.
• 10-30-2005
howeezy
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.
• 10-30-2005
7stud
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]?
• 10-30-2005
howeezy
part of a string
• 10-30-2005
7stud
What are the individual things that make up a string called?

"part of a string" is not a C++ type. :)
• 10-30-2005
howeezy
char
• 10-30-2005
7stud
Correct! Now, post a line of code that declares a char variable and assigns it a letter.
• 10-30-2005
howeezy
Code:

`char stud7='x';`
• 10-30-2005
7stud
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?
• 10-30-2005
howeezy
ah thank you :)