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

A concise, practical checklist to get the Tic-Tac-Toe code compiling and behaving as intended. already called out typos and missing braces; the problems are mostly syntactic and a few logic-pattern mistakes rather than algorithmic. The key areas to fix: modern headers and namespacing, proper board initialization and variable scope, correct input-validation, correct use of comparison/logical operators, a single clear move counter, and a compact win-check routine.

Short prioritized fixes

  • Use standard headers and namespace: #include <iostream> and std::cout / std::cin (avoid old <iostream.h> and nonportable conio.h / system("PAUSE")).
  • Initialize the board to a printable empty value (e.g. space ' ' or '-') and do that once before the main play loop. Declare loop counters and the move counter in the smallest useful scope.
  • Validate input with a re-prompting loop that checks row/column ranges and whether board[r-1][c-1] is empty. Only write to the board after validation and then increment the move counter.
  • Do not chain equality like a == b == c (this compares a bool to a char). Test pairwise or use a loop. Avoid nonsense expressions like applying ++ to a comparison.
  • Keep the win test concise and centralized; check rows, columns and the two diagonals with a small helper function.

Example helper functions (drop into a C++ source that uses std::):

bool winner(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;
    if (b[0][i]==p && b[1][i]==p && b[2][i]==p) return true;
  }
  if (b[0][0]==p && b[1][1]==p && b[2][2]==p) return true;
  if (b[2][0]==p && b[1][1]==p && b[0][2]==p) return true;
  return false;
}

void get_move(char b[3][3], int &r, int &c) {
  while (true) {
    std::cin >> r >> c;
    if (r>=1 && r<=3 && c>=1 && c<=3 && b[r-1][c-1]==' ') break;
    std::cout << "Invalid move, try again\n";
  }
}

Practical debugging tips: compile early and often (e.g. g++ -std=c++17 -Wall -Wextra), fix one compiler error at a time, use an editor with brace matching, and keep the main loop simple: alternate players, call get_move, update board, increment moves, call winner, then exit on win or when moves == 9. For , ensure cou() is declared or defined before use so the compiler sees it.

I have looked over the code and got it working. However, I guess I cannot post the code or I could lose reputation. The big thing I you should do is reread your code because I found lots of typos and missing statement endings '}'. Also, take a look at your for() loops

for(;i>3||i<1||j>3||j<1||'X'==matrix[i-1][j-1]||'O'++matrix[i-1][j-1];)

and right below your for() loop if you read it it pretty much says unless there is an error on input I'm not going to add the initial input to the matrix.

You also have a line above player 1's turn that says if( sum == 0 ) then its his turn. Sum is only equal to zero on the first turn so that would mean player 1 only gets to have one turn.

It's just a bunch of minor bugs that turn it into a major mess. If after fixing up the things stated above you still have problems just ask I have it all done.

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.