| | |
Tic tac toe program.....help needed
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Sep 2009
Posts: 4
Reputation:
Solved Threads: 0
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";
}
#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";
}
![]() |
Similar Threads
- Confused on how to finish Tic Tac Toe program. (C++)
- Tic-Tac-Toe (C++)
- C++ help with tic tac toe program (C++)
- Tic Tac Toe Help (Java)
- Continued Tic Tac Toe help (C)
- Tic Tac Toe Homework (C++)
Other Threads in the C++ Forum
- Previous Thread: Need help on homework assignment
- Next Thread: Loop help - a beginners plea
| Thread Tools | Search this Thread |
api array beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion count data database delete desktop developer directshow dll download dynamic email encryption error file forms fstream function functions game getline google graph gui homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates test text text-file tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






