Thread: Tic tac toe win

  1. #1
    Your Father
    Join Date
    Sep 2005
    Posts
    34

    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. #2
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    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]?
    Last edited by 7stud; 10-30-2005 at 01:08 PM.

  3. #3
    Your Father
    Join Date
    Sep 2005
    Posts
    34
    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. #4
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    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. #5
    Your Father
    Join Date
    Sep 2005
    Posts
    34
    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. #6
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    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]?
    Last edited by 7stud; 10-30-2005 at 01:22 PM.

  7. #7
    Your Father
    Join Date
    Sep 2005
    Posts
    34
    part of a string

  8. #8
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    What are the individual things that make up a string called?

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

  9. #9
    Your Father
    Join Date
    Sep 2005
    Posts
    34
    char

  10. #10
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    Correct! Now, post a line of code that declares a char variable and assigns it a letter.

  11. #11
    Your Father
    Join Date
    Sep 2005
    Posts
    34
    Code:
    char stud7='x';

  12. #12
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    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. #13
    Your Father
    Join Date
    Sep 2005
    Posts
    34
    ah thank you

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help me with my simple Tic tac toe prog
    By maybnxtseasn in forum C Programming
    Replies: 2
    Last Post: 04-04-2009, 06:25 PM
  2. Tic Tac Toe... so close...
    By SlayerBlade in forum C Programming
    Replies: 14
    Last Post: 10-10-2005, 08:58 PM
  3. Help with Tic Tac Toe game
    By snef73 in forum C++ Programming
    Replies: 1
    Last Post: 04-25-2003, 08:33 AM
  4. my tic tac toe game, please try it
    By Leeman_s in forum C++ Programming
    Replies: 2
    Last Post: 04-14-2002, 05:16 PM
  5. checking for win in tic tac toe
    By Leeman_s in forum C++ Programming
    Replies: 1
    Last Post: 04-13-2002, 01:31 PM