Tic Tac Toe Program Question

This is a discussion on Tic Tac Toe Program Question within the C++ Programming forums, part of the General Programming Boards category; I'll start by saying that I don't know much about programming... but I was trying to make a program that ...

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    25

    Tic Tac Toe Program Question

    I'll start by saying that I don't know much about programming... but I was trying to make a program that would let two users play a game of tic tac toe... I apparently have a lot of debugging to do and I have no idea at all where to start... at the end of this message is my source code.. if anyone could debug it for me.. or help me to debug it.. that would be spectacular


    Code:
    #include <iostream>
    using namespace std;
    
    
    int gameStatus()
    {
    // To check if player one has won
    if (gameboard[0][0] == 'X' && gameboard[0][1] == 'X' && gameboard[0][2] == 'X' ||
        gameboard[1][0] == 'X' && gameboard[1][1] == 'X' && gameboard[1][2] == 'X' ||
        gameboard[2][0] == 'X' && gameboard[2][1] == 'X' && gameboard[2][2] == 'X' ||
        gameboard[0][0] == 'X' && gameboard[1][0] == 'X' && gameboard[2][0] == 'X' ||
        gameboard[0][1] == 'X' && gameboard[1][1] == 'X' && gameboard[2][1] == 'X' ||
        gameboard[0][2] == 'X' && gameboard[1][2] == 'X' && gameboard[2][2] == 'X' ||
        gameboard[0][0] == 'X' && gameboard[1][1] == 'X' && gameboard[2][2] == 'X' ||
        gameboard[0][2] == 'X' && gameboard[1][1] == 'X' && gameboard[2][0] == 'X')
        return 1;
    // To check if player two has won
    else if (gameboard[0][0] == 'O' && gameboard[0][1] == 'O' && gameboard[0][2] == 'O' ||
             gameboard[1][0] == 'O' && gameboard[1][1] == 'O' && gameboard[1][2] == 'O' ||
             gameboard[2][0] == 'O' && gameboard[2][1] == 'O' && gameboard[2][2] == 'O' ||
             gameboard[0][0] == 'O' && gameboard[1][0] == 'O' && gameboard[2][0] == 'O' ||
             gameboard[0][1] == 'O' && gameboard[1][1] == 'O' && gameboard[2][1] == 'O' ||
             gameboard[0][2] == 'O' && gameboard[1][2] == 'O' && gameboard[2][2] == 'O' ||
             gameboard[0][0] == 'O' && gameboard[1][1] == 'O' && gameboard[2][2] == 'O' ||
             gameboard[0][2] == 'O' && gameboard[1][1] == 'O' && gameboard[2][0] == 'O')
             return 2;
    // To check for a tie
    else if (gameboard[0][0] != ' ' && gameboard[0][1] != ' ' && gameboard[0][2] != ' ' &&
             gameboard[1][0] != ' ' && gameboard[1][1] != ' ' && gameboard[1][2] != ' ' &&
             gameboard[2][0] != ' ' && gameboard[2][1] != ' ' && gameboard[2][2] != ' ')
             return 0;
    // Otherwise continue..
    else 
    return 3;
    
        
        
    }
    
    
    
    
    
    
    
    
    
    void displayBoard()
    {
    // Used to display the gameboard
    cout << gameboard[0][0] << "|" << gameboard[0][1] << "|" << gameboard[0][2] << "---------";
    cout << gameboard[1][0] << "|" << gameboard[1][1] << "|" << gameboard[1][2] << "---------";
    cout << gameboard[2][0] << "|" << gameboard[2][1] << "|" << gameboard[2][2];
         
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    int main()
    {
        
        int x=0, y=0, n;
        char name1[15], name2[15];
        char gameboard[3][3] = {" ", " ", " ", " ", " ", " ", " ", " ", " "};
        
    //Welcome and initialize everything    
        cout << "Welcome to this game of Tic Tac Toe" << "\n";
        cout << "First player, enter your name:" << "\n";
        cin >> name1;
        cout << "Second player, enter your name:" << "\n";
        cin >> name2;
        cout << "__|__|__" << "\n" << "__|__|__" << "\n" << "  |  |  " << "\n";
        cout << "You make a move by entering first the row number and then the column number\n";
        
    
        
        
        
    //Start game    
        for (n = 0, n < 9, n++)
        {
            
            
            
            
            
        
    // This if statement is for player one's moves
        if (n / 2 &#37; 1)
        { 
          cout << name1 << ", make your move: ";
          cin >> x;
          cin >> y;
    
          while (gameboard[x - 1][y - 1] != " ")
          {
              cout << "\n" << "Illegal move, make another move:"
              cin >> x;
              cin >> y;
          }
          gameboard[x][y] = "X";
          displayBoard();
          
          
          
          if (gameStatus() == 1)
          {
               cout << name1 << " has won!";
               exit(1);
          }
          else if (gameStatus() == 2)
          {
               cout << name2 << " has won!";
               exit(1);
          }
          else if (gameStatus() == 0)
          {
               cout << "Game tied";
               exit(1);
          }
          else
          break;
        }
        
        
        
        
        
        
        
    //This if statement is for player two's moves    
        if (n / 2 % 0)
        { 
          cout << name2 << ", make your move: ";
          cin >> x;
          cin >> y;
    
          while (gameboard[x - 1][y - 1] != " ")
          {
              cout << "\n" << "Illegal move, make another move:"
              cin >> x;
              cin >> y;
          }
          gameboard[x][y] = "O";
          displayBoard();
                
                
          if (gameStatus() == 1)
          {
               cout << name1 << " has won!";
               exit(1);
          }
          else if (gameStatus() == 2)
          {
               cout << name2 << " has won!";
               exit(1);
          }
          else if (gameStatus() == 0)
          {
               cout << "Game tied";
               exit(1);
          }
          else
          break;
        }
        
        
        
        
        
        
        }
    }
        
        
        
        
        
        
     
    }

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Do you have a compiler? You should read the warnings:
    Quote Originally Posted by gcc
    mingw32-g++.exe -pedantic -W -Wall -g -c "C:\Documents and Settings\Andrew\Desktop\temp.cpp" -o "C:\Documents and Settings\Andrew\Desktop\temp.o"
    C:\Documents and Settings\Andrew\Desktop\temp.cpp: In function `int gameStatus()':
    C:\Documents and Settings\Andrew\Desktop\temp.cpp:8: error: `gameboard' was not declared in this scope
    C:\Documents and Settings\Andrew\Desktop\temp.cpp: In function `void displayBoard()':
    C:\Documents and Settings\Andrew\Desktop\temp.cpp:51: error: `gameboard' was not declared in this scope
    C:\Documents and Settings\Andrew\Desktop\temp.cpp: In function `int main()':
    C:\Documents and Settings\Andrew\Desktop\temp.cpp:77: error: too many initializers for `char[3][3]'
    C:\Documents and Settings\Andrew\Desktop\temp.cpp:93: warning: right-hand operand of comma has no effect
    C:\Documents and Settings\Andrew\Desktop\temp.cpp:93: error: expected `;' before ')' token
    C:\Documents and Settings\Andrew\Desktop\temp.cpp:186: error: expected primary-expression before '}' token
    C:\Documents and Settings\Andrew\Desktop\temp.cpp:186: error: expected `;' before '}' token
    C:\Documents and Settings\Andrew\Desktop\temp.cpp:186: error: expected primary-expression before '}' token
    C:\Documents and Settings\Andrew\Desktop\temp.cpp:186: error: expected `)' before '}' token
    C:\Documents and Settings\Andrew\Desktop\temp.cpp:186: error: expected primary-expression before '}' token
    C:\Documents and Settings\Andrew\Desktop\temp.cpp:186: error: expected `;' before '}' token
    C:\Documents and Settings\Andrew\Desktop\temp.cpp:75: warning: unused variable 'x'
    C:\Documents and Settings\Andrew\Desktop\temp.cpp:75: warning: unused variable 'y'
    C:\Documents and Settings\Andrew\Desktop\temp.cpp:77: warning: unused variable 'gameboard'
    C:\Documents and Settings\Andrew\Desktop\temp.cpp: At global scope:
    C:\Documents and Settings\Andrew\Desktop\temp.cpp:194: error: expected declaration before '}' token
    Process terminated with status 1 (0 minutes, 2 seconds)
    11 errors, 4 warnings
    • So you need to pass the gameboard to all your functions, otherwise they won't know what the heck is going on.
    • You get characters by using 'single quotes', not "double quotes" -- so that's why your initializer of gameboard complains.
    • You need to look at the syntax of "for" again, hence all the "expected ;" errors.

  3. #3
    Registered User
    Join Date
    Apr 2008
    Posts
    25
    Yea I have a compiler
    I just don't know how to go about fixing the errors
    Right now I'm trying to go through it and fix what I can...

  4. #4
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,167
    It's often not a good idea to write a truckload of code at a time then start debugging. People usually add few lines at a time, and making sure it works after each addition.

  5. #5
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by Unknowntoyou000 View Post
    Yea I have a compiler
    I just don't know how to go about fixing the errors
    Right now I'm trying to go through it and fix what I can...
    The beauty of compiler errors is that they tell you how to fix them. When it says "gameboard not declared in this scope" -- that means that the function where the error is doesn't know about gameboard, which means you forgot to pass the gameboard into the function. When it says "right-hand operand of comma has no effect", that means you're not supposed to have a comma there. See? Simple.

  6. #6
    Registered User
    Join Date
    Apr 2008
    Posts
    25
    Lol thanks
    I'm trying right now.. I kinda suck at this stuff though :/

  7. #7
    Registered User
    Join Date
    Apr 2008
    Posts
    25
    One big question..
    the error.. too many initializers for `char[3][3]'
    for the code that looks like:
    char gameboard[3][3] = { " ", " ", " ", " ", " ", " ", " ", " ", " "};
    I don't get this one... I have 9 initializers.. isn't that allowed?
    Last edited by Unknowntoyou000; 04-10-2008 at 07:41 PM.

  8. #8
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by Unknowntoyou000 View Post
    One big question..
    the error.. too many initializers for `char[3][3]'
    I don't get this one... I have 9 initializers.. isn't that allowed?
    You have nine things -- but they're not characters, they are themselves arrays of characters. IOW: " " is not a character, it is a character array (consisting of the character ' ' -- note the difference -- and the character '\0'). Since you are initializing with arrays of characters, you are only allowed three.

    Edit: And of course, you want characters, not character arrays, so you should change them to characters.

  9. #9
    Registered User
    Join Date
    Apr 2008
    Posts
    25
    Ok thanks I fixed that problem.. lol


    Wanna help with another one? -_-'

    Code:
    int gameStatus(char gameboard)
    {
    // To check if player one has won
    if (gameboard[0][0] == 'X' && gameboard[0][1] == 'X' && gameboard[0][2] == 'X' ||
        gameboard[1][0] == 'X' && gameboard[1][1] == 'X' && gameboard[1][2] == 'X' ||
        gameboard[2][0] == 'X' && gameboard[2][1] == 'X' && gameboard[2][2] == 'X' ||
        gameboard[0][0] == 'X' && gameboard[1][0] == 'X' && gameboard[2][0] == 'X' ||
        gameboard[0][1] == 'X' && gameboard[1][1] == 'X' && gameboard[2][1] == 'X' ||
        gameboard[0][2] == 'X' && gameboard[1][2] == 'X' && gameboard[2][2] == 'X' ||
        gameboard[0][0] == 'X' && gameboard[1][1] == 'X' && gameboard[2][2] == 'X' ||
        gameboard[0][2] == 'X' && gameboard[1][1] == 'X' && gameboard[2][0] == 'X')
        return 1;
    // To check if player two has won
    else if (gameboard[0][0] == 'O' && gameboard[0][1] == 'O' && gameboard[0][2] == 'O' ||
             gameboard[1][0] == 'O' && gameboard[1][1] == 'O' && gameboard[1][2] == 'O' ||
             gameboard[2][0] == 'O' && gameboard[2][1] == 'O' && gameboard[2][2] == 'O' ||
             gameboard[0][0] == 'O' && gameboard[1][0] == 'O' && gameboard[2][0] == 'O' ||
             gameboard[0][1] == 'O' && gameboard[1][1] == 'O' && gameboard[2][1] == 'O' ||
             gameboard[0][2] == 'O' && gameboard[1][2] == 'O' && gameboard[2][2] == 'O' ||
             gameboard[0][0] == 'O' && gameboard[1][1] == 'O' && gameboard[2][2] == 'O' ||
             gameboard[0][2] == 'O' && gameboard[1][1] == 'O' && gameboard[2][0] == 'O')
             return 2;
    // To check for a tie
    else if (gameboard[0][0] != ' ' && gameboard[0][1] != ' ' && gameboard[0][2] != ' ' &&
             gameboard[1][0] != ' ' && gameboard[1][1] != ' ' && gameboard[1][2] != ' ' &&
             gameboard[2][0] != ' ' && gameboard[2][1] != ' ' && gameboard[2][2] != ' ')
             return 0;
    // Otherwise continue..
    else 
    return 3;
    
        
        
    }
    Obviously I don't know how to pass gameboard[][] to this function..
    The error I receive is:
    invalid types `char[int]' for array subscript

  10. #10
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    gameboard isn't a char, so don't try to convince the compiler that it is. It's a char[3][3], isn't it? So:
    Code:
    int gameStatus(char gameboard[3][3])

  11. #11
    Registered User
    Join Date
    Apr 2008
    Posts
    25
    lol yea I know
    I still have a lot of errors to deal with.. and I really don't see what's wrong with most of the stuff....

    my code now looks like
    Code:
    #include <iostream>
    using namespace std;
    
    
    int gameStatus(char gameboard[3][3]))
    {
    // To check if player one has won
    if (gameboard[0][0] == 'X' && gameboard[0][1] == 'X' && gameboard[0][2] == 'X' ||
        gameboard[1][0] == 'X' && gameboard[1][1] == 'X' && gameboard[1][2] == 'X' ||
        gameboard[2][0] == 'X' && gameboard[2][1] == 'X' && gameboard[2][2] == 'X' ||
        gameboard[0][0] == 'X' && gameboard[1][0] == 'X' && gameboard[2][0] == 'X' ||
        gameboard[0][1] == 'X' && gameboard[1][1] == 'X' && gameboard[2][1] == 'X' ||
        gameboard[0][2] == 'X' && gameboard[1][2] == 'X' && gameboard[2][2] == 'X' ||
        gameboard[0][0] == 'X' && gameboard[1][1] == 'X' && gameboard[2][2] == 'X' ||
        gameboard[0][2] == 'X' && gameboard[1][1] == 'X' && gameboard[2][0] == 'X')
        return 1;
    // To check if player two has won
    else if (gameboard[0][0] == 'O' && gameboard[0][1] == 'O' && gameboard[0][2] == 'O' ||
             gameboard[1][0] == 'O' && gameboard[1][1] == 'O' && gameboard[1][2] == 'O' ||
             gameboard[2][0] == 'O' && gameboard[2][1] == 'O' && gameboard[2][2] == 'O' ||
             gameboard[0][0] == 'O' && gameboard[1][0] == 'O' && gameboard[2][0] == 'O' ||
             gameboard[0][1] == 'O' && gameboard[1][1] == 'O' && gameboard[2][1] == 'O' ||
             gameboard[0][2] == 'O' && gameboard[1][2] == 'O' && gameboard[2][2] == 'O' ||
             gameboard[0][0] == 'O' && gameboard[1][1] == 'O' && gameboard[2][2] == 'O' ||
             gameboard[0][2] == 'O' && gameboard[1][1] == 'O' && gameboard[2][0] == 'O')
             return 2;
    // To check for a tie
    else if (gameboard[0][0] != ' ' && gameboard[0][1] != ' ' && gameboard[0][2] != ' ' &&
             gameboard[1][0] != ' ' && gameboard[1][1] != ' ' && gameboard[1][2] != ' ' &&
             gameboard[2][0] != ' ' && gameboard[2][1] != ' ' && gameboard[2][2] != ' ')
             return 0;
    // Otherwise continue..
    else 
    return 3;
    
        
        
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    void displayBoard(char gameboard[3][3])
    {
    // Used to display the gameboard
    cout << gameboard[0][0] << "|" << gameboard[0][1] << "|" << gameboard[0][2] << "---------";
    cout << gameboard[1][0] << "|" << gameboard[1][1] << "|" << gameboard[1][2] << "---------";
    cout << gameboard[2][0] << "|" << gameboard[2][1] << "|" << gameboard[2][2];
         
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    int main()
    {
        
        int x=0, y=0, n;
        char name1[15], name2[15];
        char gameboard[3][3] = {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '};
        
    //Welcome and initialize everything    
        cout << "Welcome to this game of Tic Tac Toe" << "\n";
        cout << "First player, enter your name:" << "\n";
        cin >> name1;
        cout << "Second player, enter your name:" << "\n";
        cin >> name2;
        cout << "__|__|__" << "\n" << "__|__|__" << "\n" << "   |   |   " << "\n";
        cout << "You make a move by entering first the row number and then the column number" << "\n";
        
    
        
        
        
    //Start game    
        for (n = 0, n < 9, n++)
        {
            
            
            
            
            
        
    // This if statement is for player one's moves
        if (n / 2 &#37; 1)
        { 
          cout << name1 << ", make your move: ";
          cin >> x;
          cin >> y;
    
          while (gameboard[x - 1][y - 1] != " ")
          {
              cout << "\n" << "Illegal move, make another move:"
              cin >> x;
              cin >> y;
          }
          gameboard[x][y] = "X";
          displayBoard();
          
          
          
          if (gameStatus() == 1)
          {
               cout << name1 << " has won!";
               exit(1);
          }
          else if (gameStatus() == 2)
          {
               cout << name2 << " has won!";
               exit(1);
          }
          else if (gameStatus() == 0)
          {
               cout << "Game tied";
               exit(1);
          }
          else
          break;
        }
        
        
        
        
        
        
        
    //This if statement is for player two's moves    
        else if (n / 2 % 0)
        { 
          cout << name2 << ", make your move: ";
          cin >> x;
          cin >> y;
    
          while (gameboard[x - 1][y - 1] != " ")
          {
              cout << "\n" << "Illegal move, make another move:"
              cin >> x;
              cin >> y;
          }
          gameboard[x][y] = "O";
          displayBoard();
                
                
          if (gameStatus() == 1)
          {
               cout << name1 << " has won!";
               exit(1);
          }
          else if (gameStatus() == 2)
          {
               cout << name2 << " has won!";
               exit(1);
          }
          else if (gameStatus() == 0)
          {
               cout << "Game tied";
               exit(1);
          }
          else
          break;
        }
        else
        break;
        
        
        
        
        
        }
    }
    }
    and I think everything is just syntax errors.. but ones that I don't know how to fix.. doesn't make any sense to me....
    errors:
    5 expected init-declarator before ')' token
    5 expected `,' or `;' before ')' token
    In function `int main()':
    125 expected `;' before ')' token
    219 expected primary-expression before '}' token
    219 expected `;' before '}' token
    219 expected primary-expression before '}' token
    219 expected `)' before '}' token
    219 expected primary-expression before '}' token
    219 expected `;' before '}' token
    219 At global scope:
    220 expected declaration before '}' token
    Last edited by Unknowntoyou000; 04-10-2008 at 08:06 PM.

  12. #12
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by Unknowntoyou000 View Post
    lol yea I know
    I still have a lot of errors to deal with.. and I really don't see what's wrong with most of the stuff....

    these are the two errors I'm still getting with that line:
    int gameStatus (char gameboard[3][3])

    expected init-declarator before ')' token
    expected `,' or `;' before ')' token
    Then you've changed something else -- I made that change and did not get such error.

  13. #13
    Registered User
    Join Date
    Apr 2008
    Posts
    25
    Oh and btw
    Thanks for helping this confused soul lol

  14. #14
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by Unknowntoyou000 View Post
    lol yea I know
    I still have a lot of errors to deal with.. and I really don't see what's wrong with most of the stuff....

    my code now looks like
    Code:
    #include <iostream>
    using namespace std;
    
    
    int gameStatus(char gameboard[3][3]))
    {
    // To check if player one has won
    if (gameboard[0][0] == 'X' && gameboard[0][1] == 'X' && gameboard[0][2] == 'X' ||
        gameboard[1][0] == 'X' && gameboard[1][1] == 'X' && gameboard[1][2] == 'X' ||
        gameboard[2][0] == 'X' && gameboard[2][1] == 'X' && gameboard[2][2] == 'X' ||
        gameboard[0][0] == 'X' && gameboard[1][0] == 'X' && gameboard[2][0] == 'X' ||
        gameboard[0][1] == 'X' && gameboard[1][1] == 'X' && gameboard[2][1] == 'X' ||
        gameboard[0][2] == 'X' && gameboard[1][2] == 'X' && gameboard[2][2] == 'X' ||
        gameboard[0][0] == 'X' && gameboard[1][1] == 'X' && gameboard[2][2] == 'X' ||
        gameboard[0][2] == 'X' && gameboard[1][1] == 'X' && gameboard[2][0] == 'X')
        return 1;
    // To check if player two has won
    else if (gameboard[0][0] == 'O' && gameboard[0][1] == 'O' && gameboard[0][2] == 'O' ||
             gameboard[1][0] == 'O' && gameboard[1][1] == 'O' && gameboard[1][2] == 'O' ||
             gameboard[2][0] == 'O' && gameboard[2][1] == 'O' && gameboard[2][2] == 'O' ||
             gameboard[0][0] == 'O' && gameboard[1][0] == 'O' && gameboard[2][0] == 'O' ||
             gameboard[0][1] == 'O' && gameboard[1][1] == 'O' && gameboard[2][1] == 'O' ||
             gameboard[0][2] == 'O' && gameboard[1][2] == 'O' && gameboard[2][2] == 'O' ||
             gameboard[0][0] == 'O' && gameboard[1][1] == 'O' && gameboard[2][2] == 'O' ||
             gameboard[0][2] == 'O' && gameboard[1][1] == 'O' && gameboard[2][0] == 'O')
             return 2;
    // To check for a tie
    else if (gameboard[0][0] != ' ' && gameboard[0][1] != ' ' && gameboard[0][2] != ' ' &&
             gameboard[1][0] != ' ' && gameboard[1][1] != ' ' && gameboard[1][2] != ' ' &&
             gameboard[2][0] != ' ' && gameboard[2][1] != ' ' && gameboard[2][2] != ' ')
             return 0;
    // Otherwise continue..
    else 
    return 3;
    
        
        
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    void displayBoard(char gameboard[3][3])
    {
    // Used to display the gameboard
    cout << gameboard[0][0] << "|" << gameboard[0][1] << "|" << gameboard[0][2] << "---------";
    cout << gameboard[1][0] << "|" << gameboard[1][1] << "|" << gameboard[1][2] << "---------";
    cout << gameboard[2][0] << "|" << gameboard[2][1] << "|" << gameboard[2][2];
         
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    int main()
    {
        
        int x=0, y=0, n;
        char name1[15], name2[15];
        char gameboard[3][3] = {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '};
        
    //Welcome and initialize everything    
        cout << "Welcome to this game of Tic Tac Toe" << "\n";
        cout << "First player, enter your name:" << "\n";
        cin >> name1;
        cout << "Second player, enter your name:" << "\n";
        cin >> name2;
        cout << "__|__|__" << "\n" << "__|__|__" << "\n" << "   |   |   " << "\n";
        cout << "You make a move by entering first the row number and then the column number" << "\n";
        
    
        
        
        
    //Start game    
        for (n = 0, n < 9, n++)
        {
            
            
            
            
            
        
    // This if statement is for player one's moves
        if (n / 2 % 1)
        { 
          cout << name1 << ", make your move: ";
          cin >> x;
          cin >> y;
    
          while (gameboard[x - 1][y - 1] != " ")
          {
              cout << "\n" << "Illegal move, make another move:"
              cin >> x;
              cin >> y;
          }
          gameboard[x][y] = "X";
          displayBoard();
          
          
          
          if (gameStatus() == 1)
          {
               cout << name1 << " has won!";
               exit(1);
          }
          else if (gameStatus() == 2)
          {
               cout << name2 << " has won!";
               exit(1);
          }
          else if (gameStatus() == 0)
          {
               cout << "Game tied";
               exit(1);
          }
          else
          break;
        }
        
        
        
        
        
        
        
    //This if statement is for player two's moves    
        else if (n / 2 % 0)
        { 
          cout << name2 << ", make your move: ";
          cin >> x;
          cin >> y;
    
          while (gameboard[x - 1][y - 1] != " ")
          {
              cout << "\n" << "Illegal move, make another move:"
              cin >> x;
              cin >> y;
          }
          gameboard[x][y] = "O";
          displayBoard();
                
                
          if (gameStatus() == 1)
          {
               cout << name1 << " has won!";
               exit(1);
          }
          else if (gameStatus() == 2)
          {
               cout << name2 << " has won!";
               exit(1);
          }
          else if (gameStatus() == 0)
          {
               cout << "Game tied";
               exit(1);
          }
          else
          break;
        }
        else
        break;
        
        
        
        
        
        }
    }
    }
    and I think everything is just syntax errors.. but ones that I don't know how to fix.. doesn't make any sense to me....
    errors:
    5 expected init-declarator before ')' token
    5 expected `,' or `;' before ')' token
    In function `int main()':
    125 expected `;' before ')' token
    219 expected primary-expression before '}' token
    219 expected `;' before '}' token
    219 expected primary-expression before '}' token
    219 expected `)' before '}' token
    219 expected primary-expression before '}' token
    219 expected `;' before '}' token
    219 At global scope:
    220 expected declaration before '}' token
    You've got an extra ) at the end of line 5.

    You still need to read the syntax of for-loops. HINT: There are no commas.

  15. #15
    Registered User
    Join Date
    Apr 2008
    Posts
    25
    oh ok thanks

    Oh lol -_-''

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Tic Tac Toe program
    By muzihc in forum C Programming
    Replies: 10
    Last Post: 10-21-2008, 08:08 PM
  2. Tic Tac Toe... so close...
    By SlayerBlade in forum C Programming
    Replies: 14
    Last Post: 10-10-2005, 08:58 PM
  3. My first "real" C++ program! (Tic Tac Toe)
    By Loctan in forum C++ Programming
    Replies: 6
    Last Post: 03-09-2005, 02:04 PM
  4. Tic Tac Toe AI help please...
    By Rune Hunter in forum Game Programming
    Replies: 12
    Last Post: 11-05-2004, 03:24 PM
  5. tic tac toe
    By holden in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 05-09-2004, 09:59 AM

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