aneesh kalra
Mclaren F1 Long tail
c++
Here i have referred to c as a char variable which is checked whether it contains another char variable p1 or p2 which hold the symbols of the two players in this game respectively.However c++ shows syntax error when I declare c as a char variable.how can i execute this piece of code.Actually it saves me the hassle of writing two seperate check functions for player 1 and player 2 .
Here is the complete code for my tic tac toe game .
Code:
while(i<3){
if(tc[i]==c,c,c)
flag=1;
Here is the complete code for my tic tac toe game .
Code:
//Program to run game tic toe
#include<iostream.h>
#include<conio.h>
char player1,player2;
int i=0,j=0,x=0,y=0;
char tc[3][3];
char p1,p2;
int flag=0;
void display(char )
{
for(;i<3;i++)
{
for(;j<3;j++)
cout<<tc[i][j];
}}
void check(char ,char )
{
while(i<3){
if(tc[i]==c,c,c)
flag=1;
}
while(j<3){
if(tc[j]==c,c,c)
flag=1;
}
while(i<j){
if(tc[i][j]==c,c,c)
flag=1;
}
while(i==j){
if(tc[i][j]==c,c,c)
flag=1;
}
if(flag==1){
if(c==p1){
cout<<player1<<"\t has won the game";
}
if(c==p2){
cout<<player2<<"\t has won the game";
}}}
void pos(int i,int j,char c)
{
tc[i][j]=c;
if(i>3,j>3,tc[i][j]!='\0')
cout<<"\n Invalid choice";
}
void initialize(char )
{
for (i=0;i<3;i++)
{
for (j=0;j<3;j++)
tc[i][j]='A';
}}
void main(){
cout<<"Welcome to the world of tic toe gaming"<<"\n Program design and compilation by Aneesh";
cout<<"\n Please enter your names player 1 and player2 in that order";
cin>>player1>>player2;
cout<<"\n"<<player1<<"\t please enter you symbol of choice ";
cin>>p1;
cout<<"\n"<<player2<<"\t please enter your symbol of choice ";
cin>>p2;
while(flag!=1)
cout<<"\n"<< player1<<"\t please specify the position in terms of x and y where you want to place your symbol alongiwth it;ie; your symbo";
cin>>x>>y;
display(tc[3][3]);
pos(x,y,p1);
check(p1, tc[3][3]);
cout<<"\n"<<player2<<"\t please specify the position in terms of x and y where you want to place your symbol alongwith it ;i.e;your symbol";
cin>>x>>y;
display( tc[3][3]);
pos(x,y,p2);
check(p2,tc[3][3]);
cout<<"\n Thank you for playing tic toe with us";
getch();
}