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; do I use ';' then? lol...

  1. #16
    Registered User
    Join Date
    Apr 2008
    Posts
    25
    do I use ';' then? lol

  2. #17
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by Unknowntoyou000 View Post
    do I use ';' then? lol
    Yes.

  3. #18
    Registered User
    Join Date
    Apr 2008
    Posts
    25
    Ok I just did a sweep and fixed a lot of errors... I still have a few though
    I have 5 errors left to go lol
    thanks for helping me so far.. I would've probably just given up without help :/

  4. #19
    Registered User
    Join Date
    Apr 2008
    Posts
    25
    Errors:
    In function `int main()':
    177 [Warning] division by zero in `(n / 2) % 0'
    177 At global scope:
    220 expected declaration before '}' token

    With code:
    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(gameboard);
          
          
          
          if (gameStatus(gameboard) == 1)
          {
               cout << name1 << " has won!";
               exit(1);
          }
          else if (gameStatus(gameboard) == 2)
          {
               cout << name2 << " has won!";
               exit(1);
          }
          else if (gameStatus(gameboard) == 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(gameboard);
                
                
          if (gameStatus(gameboard) == 1)
          {
               cout << name1 << " has won!";
               exit(1);
          }
          else if (gameStatus(gameboard) == 2)
          {
               cout << name2 << " has won!";
               exit(1);
          }
          else if (gameStatus(gameboard) == 0)
          {
               cout << "Game tied";
               exit(1);
          }
          else
          break;
        }
        else
        break;
        
        
        
        
        
        }
    }
    }

  5. #20
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by Unknowntoyou000 View Post
    Errors:
    In function `int main()':
    177 [Warning] division by zero in `(n / 2) % 0'
    177 At global scope:
    220 expected declaration before '}' token
    So don't divide by zero then. I think you mean n%2==0, perhaps. You are checking to see if n is even, yes?

    I don't know where line 220 is, but make sure your curly braces match up where you expect.

  6. #21
    Registered User
    Join Date
    Apr 2008
    Posts
    25
    oh yea thanks.. ok I'll see what I can do... *goes to fix errors!*

  7. #22
    Registered User
    Join Date
    Apr 2008
    Posts
    25
    only one error left:
    220 expected declaration before '}' token
    which is the last line btw

  8. #23
    Registered User
    Join Date
    Apr 2008
    Posts
    25
    Oh I think I had an extra }
    I deleted it

  9. #24
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Count your open-curly-braces. Count your close-curly-braces. Note that they are not the same. Remove extras.

    Also: I hope you also fixed n/2%1, which also doesn't mean anything (just like n/2%0 didn't mean anything).

  10. #25
    Registered User
    Join Date
    Apr 2008
    Posts
    25
    I did
    thanks

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

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