I have been working on this assignment for a while. I have read a couple other threads in this site regarding similar solutions but I feel mine might be a little more unique. This tic-tac-toe board is user entered, simply setup as 9 characters in 3x3 format.
Input should look something like this:
xxo
.ox
o.x

The above would output, as well as the actual board itself(something similar to what I have shown below):

x | x | x
---------
| o | x
---------
o | | x

Then determine the winner. After it determines the winner, it will ask if the player would like to play another game.

This is not a 2 player game. It's quite simple, but quite frustrating and I'm a bit stuck. My code is not working. Take a look at what I have. It may seem all over the place...any suggestions are much appreciated. Thank you.

#include <cstdlib>
#include <iostream>

using namespace std;

void input (char board [3][3]);
void print (char board [3][3]);
bool win   (char board [3][3], char player);

int main(int argc, char *argv[])
{
    char board [3][3]= {0}; //tic tac toe board
    int row, col;                         //current row and column in the array
    char x,o ;
    char space;                           //characters to be placed into the board
    char player;                          //player of the tic tac toe game
    char play;                            //play again
    bool game_over;                       //game over
    
	
    while (play != 'n');
{	

	input (board);
	print (board);
	win (board, player);	

//Determines winner of the game	
	if (win (board, 'x'))
	    cout << "x wins!";
	    else if(win (board, 'o'))
	    cout << "o wins!";
	    else
	    cout << "No winner!";
	    
//Prompts user if want to play again
 cout << "Would you like to play again (y or n)?: "<<endl;
 cin >> play;
 
 if (play == 'y')
 {
          game_over = false; //game will continue.
          }
          else if (play == 'n')
          {
               game_over = true; //game will not continue
               cout << "Thanks for playing!" << endl;
               return 1;
               }
               else 
               { 
                    cout << "Invalid answer! Try again!" << endl;
                    cin >> play;
                    }
 
}   
    system("PAUSE");
    return EXIT_SUCCESS;
}


//What is being read in from the user
void input (char board [3][3])
{
  char r,c; //current row and col

  cout << "Enter your board as characters (x, o, .):   "<< endl;
  
    
    for (r = 0; r < 3; r++)
    {
        for (char c = 0; c < 3; c++)
        {
            cin >> board [r][c];
            }
    }

}
//what is being printed 
void print (char board [3][3])
{
     char r,c; //current row and col
     
     for (r = 0; r < 3; r++)
     {
         for (c = 0; c < 3; c++)
         
         cout << " " << board[r][c];
}
       //This is the start of the board setup...I got stuck here and commented it out.  
      /*
      if (board[r][c] = 'x')
         {cout << " | " << board[r][c];}
       if (r < 2)
        {cout << " | " << board[r][c];}
        
      cout << "/n---------";
      
      if (board[r][c] == '.')
       cout << "   ";
       
       if (board[r][c] == 'x')
       cout << "  |  "<<
        
        
       
       
         if (board [r][c] == 'o')
         cout << "  |  ";
           if (board [r][c] < 2)
           cout << "   ";
   
   */
   
//Decides who wins the game, 'x' or 'o' or no winner
bool win (char board [3][3], char player)
{

if
((board[0][0]==player && board[0][1]==player && board[0][2]==player)
 return true;
 
else if(board[1][0]==player && board[1][1]==player && board[1][2]==player)
 return true;
 
else if(board[2][0]==player && board[2][1]==player && board[2][2]==player)
 return true;

else if(board[0][0]==player && board[1][0]==player && board[2][0]==player)
 return true;

else if(board[0][1]==player && board[1][1]==player && board[2][1]==player)
 return true;

else if(board[0][2]==player && board[1][2]==player && board[2][2]==player)
 return true;

else if(board[0][0]==player && board[1][1]==player && board[2][2]=='player
 return true;

else if(board[0][2]==player && board[1][1]==player && board[2][0]==player)
 return true; 

else if(board[2][0]==player && board[1][1]==player && board[0][2]==player));
return true;

else
return false;
//what is being printed 
void print (char board [3][3])
{
     char r,c; //current row and col
     
     for (r = 0; r < 3; r++)
     {
         for (c = 0; c < 3; c++)
         
         cout << " " << board[r][c];
}
       //This is the start of the board setup...I got stuck here and commented it out.  
      /*
      if (board[r][c] = 'x')
         {cout << " | " << board[r][c];}
       if (r < 2)
        {cout << " | " << board[r][c];}
        
      cout << "/n---------";
      
      if (board[r][c] == '.')
       cout << "   ";
       
       if (board[r][c] == 'x')
       cout << "  |  "<<
        
        
       
       
         if (board [r][c] == 'o')
         cout << "  |  ";
           if (board [r][c] < 2)
           cout << "   ";
   
   */

Take it a step at a time. One, format your code. Get a code beautifier or use an IDE like Visual C++ which has formatting options. You have some brackets problems which will stand out much more clearly with formatted/indented code.

Every starting bracket/parentheses must have a matching ending bracket/parentheses. You can't improve the code or follow it if you can't see what bracket goes with what bracket. So that's the first step. Next point is that, if you mix tabs and spaces, every tab is the equivalent of a certain number of spaces. Usually it's four, but on Daniweb for some reason, it appears to be eight, so what may look great on your IDE may look horrible on someone else's that has a different space-to-tab ratio. since almost no one uses 8 spaces per tab, mixing tabs and spaces usually looks terrible when posting on Daniweb. Best bet is to change the tabs to spaces (many IDE's allow you to do that easily), THEN post here. It looks much better.

Also, if you put this below in code tags too:

x|x|x
-----
 |o|x
-----
o| |x

uniform Courier-like character spacing is retained and it lines up.

As to the print function, figure out what you want to display and how, and after fixing the brackets, have a nested loop as you have started to do. You are on the right track when you check whether r is equal to 2 and whether c is equal to 2 and doing something based on it. I guess a dot represents a blank space? Are you trying to display the dot or a blank space? Why not have a blank denote a blank? Anyway, I don't see the need for the if-statements on lines 14, 21, 24, 30, 32. You want to display what's on the board, no matter what it is, right? And you display the '|' character at certain spots regardless of what the board looks like, right?

I would fix the bracket problems, format/indent consistently with spaces, then go from there.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.