i am tryin to make a c++ program to play tic tac toe.........there are some errors hope u guys can help me out.........

#include<iostream.h>
#include<conio.h>
#include<stdlib.h>

char matrix[3][3];
void cou(void);
int main()
{
    int m,n;
    char ch='y';
    while(ch=='Y'||ch=='y')
    {
        for(m=0;m<3;m++)
        {
            for(n=0;n<3;n++)
            {
                matrix[m][n]='\0';
                int i,j,sum=0;
                while(sum<10)
                {
                    if(sum==0)
                    {
                        cou();
                        cout<<"Player 1 is 'X': choose row and column"<<endl;
                        cout<<"Row:";
                        cin>>i;
                        cout<<"column :";
                        cin>>j;
                        for(i>3||i<1||j>3||j<1||'X'==matrix[i-1][j-1]||'O'++matrix[i-1][j-1])
                        {
                            cout<<"\n Sorry !!! but you gotta choose another place \t";
                            cout<<"row:";
                            cin>>i;
                            cout<<"column:";
                            cin>>j;
                            matrix[i-1][j-1]='X';
                            sum++;
                            cou();
                            if(matrix[0][0]=='X'&&matrix[0][0]==matrix[1][1]&&matrix[1][1]==matrix[2][2])
                            {
                                cout<<"\n Player one wins \t";
                                break;
                            }
                            if{matrix[2][0]=='X'&&matrix[2][0]==matrix[1][1]&&matrix[1][1]==matrix[0][2])
                            {
                                cout<<"\n Player one wins \t";
                                break;
                            }
                            if(matrix[0][0]=='X'&&matrix[0][0]==matrix[1][0]&&matrix[1][0]==matrix[2][0])
                            {
                                cout<<"\n Player one wins \t";
                                break;
                            }
                            if(matrix[0][1]=='X'&&matrix[0][1]==matrix[1][1]&&matrix[1][1]==matrix[2][1])
                            {
                                cout<<"\n Player one wins \t";
                                break;
                            }
                            if{matrix[0][2]=='X'&&matrix[0][2]==matrix[1][2]&&matrix[1][2]==matrix[2][2])
                            {
                                cout<<"\n Player one wins \t";
                                break;
                            }
                            if(matrix[0][0]=='X'&&matrix[0][0]==matrix[0][1]==matrix[0][1]==matrix[0][2])
                            {
                                cout<<"\n Player one wins \t";
                                break;
                            }
                            if(matrix[1][0]=='X'&&matrix[1][0]==matrix[1][1]&&matrix[1][1]==matrix[1][2])
                            {
                                cout<<"\n Player one wins \t";
                                break;
                            }
                            if(matrix[2][0]=='X'&&matrix[2][0]==matrix[2][1]&&matrix[2][1]==matrix[2][2])
                            {
                                cout<<"\n Player one wins \t";
                                break;
                            }
                        }
                            if(sum==9)
                            (
                                cout<<"\n The game is over and noone wins  hahahaha you both stink \t";
                                break;
                            }
                            cout<<"\n Player 2 is 'O':choose row and column \t";
                            cout<<"\n Row \t";
                            cin>>i;
                            cout<<"\n Column : \t";
                            cin>>j;
                            for(;i>3||i<1||j>3||j<1||'X'==matrix[i-1][j-1]||'O'++matrix[i-1][j-1];)
                        {
                            cout<<"\n Sorry !!! but you gotta choose another place \t";
                            cout<<"row:";
                            cin>>i;
                            cout<<"column:";
                            cin>>j;
                            matrix[i-1][j-1]='O';
                            sum++;
                            cou();
                            if(matrix[0][0]=='O'&&matrix[0][0]==matrix[1][1]&&matrix[1][1]==matrix[2][2])
                            {
                                cout<<"\n Player one wins \t";
                                break;
                            }
                            if{matrix[2][0]=='O'&&matrix[2][0]==matrix[1][1]&&matrix[1][1]==matrix[0][2])
                            {
                                cout<<"\n Player one wins \t";
                                break;
                            }
                            if(matrix[0][0]=='O'&&matrix[0][0]==matrix[1][0]&&matrix[1][0]==matrix[2][0])
                            {
                                cout<<"\n Player one wins \t";
                                break;
                            }
                            if(matrix[0][1]=='O'&&matrix[0][1]==matrix[1][1]&&matrix[1][1]==matrix[2][1])
                            {
                                cout<<"\n Player one wins \t";
                                break;
                            }
                            if{matrix[0][2]=='O'&&matrix[0][2]==matrix[1][2]&&matrix[1][2]==matrix[2][2])
                            {
                                cout<<"\n Player one wins \t";
                                break;
                            }
                            if(matrix[0][0]=='O'&&matrix[0][0]==matrix[0][1]==matrix[0][1]==matrix[0][2])
                            {
                                cout<<"\n Player one wins \t";
                                break;
                            }
                            if(matrix[1][0]=='O'&&matrix[1][0]==matrix[1][1]&&matrix[1][1]==matrix[1][2])
                            {
                                cout<<"\n Player one wins \t";
                                break;
                            }
                            if(matrix[2][0]=='O'&&matrix[2][0]==matrix[2][1]&&matrix[2][1]==matrix[2][2])
                            {
                                cout<<"\n Player one wins \t";
                                break;
                            }
                            cout<<"\n Would you like to play again??(y/n)\n":
                            cin>>ch;
                        }
                        system("PAUSE");
                        return 0;
                    }
                    void cou(void)
                    {
                        cout"\n\t\t              123\n"<<endl;
                        cout<<"\t\t  1"<<matrix[0][0]<<"|"<<matrix[0][1]<<"|"<<matrix[0][2]<<endl;
                        cout<<"\t\t           ---|---|---\n";
                        cout<<"\t\t  2"<<matrix[1][0]<<"|"<<matrix[1][1]<<"|"<<matrix[1][2]<<endl;
                        cout<<"\t\t           ---|---|---\n";
                        cout<<"\t\t  2"<<matrix[2][0]<<"|"<<matrix[2][1]<<"|"<<matrix[2][2]<<"\n\n\n";
                    }

Dani AI

Generated

Quick diagnosis and a concise plan to get the posted Tic‑Tac‑Toe program compiling and behaving as intended (notes tied to 's submission and 's repost).

The code shows three classes of problems: syntax (mismatched braces/parentheses, wrong keyword placement), style/portability (old headers and nonstandard console calls), and logic (chained equality like a==b==c, improper loop/condition usage, incorrect increments and duplicated win messages). Fixing should proceed in small steps: get a minimal main that prints an empty board, then add validated input, then move placement, then win detection, then replay.

Recommended structure (high level):

  • Use modern headers (for example <iostream>) and fully qualified std:: names or a using declaration. Remove nonstandard headers and platform-specific pause calls.
  • Initialize a 3x3 board to a visible empty marker (space or '-').
  • Provide small functions: printBoard, isValidMove, makeMove, checkWin. Keep each function short and well-tested.
  • Drive the game with a single loop up to 9 moves, alternate the player by move count, validate input with a do/while until a legal cell is chosen, update the board, then call checkWin. Declare a draw when move count reaches 9 with no winner.

Example implementations to copy/test (these are new, not reproductions of the posted code):

bool checkWin(const char b[3][3], char p) {
    for (int i = 0; i < 3; ++i)
        if (b[i][0] == p && b[i][1] == p && b[i][2] == p) return true;
    for (int j = 0; j < 3; ++j)
        if (b[0][j] == p && b[1][j] == p && b[2][j] == p) return true;
    if (b[0][0] == p && b[1][1] == p && b[2][2] == p) return true;
    if (b[0][2] == p && b[1][1] == p && b[2][0] == p) return true;
    return false;
}
int r, c;
do {
    std::cin >> r >> c;
} while (r < 1 || r > 3 || c < 1 || c > 3 || board[r-1][c-1] != ' ');

Quick debugging tips: compile with warnings enabled (for example g++ -std=c++17 -Wall -Wextra), fix errors one at a time, and write small tests for checkWin and isValidMove. Start with a tiny working program that prints the board and accepts one valid move, then incrementally add features.

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.