Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  tic tic
Language: C/C++
Code:
#include <stdio.h>
#include <iostream.h>
char arr[3][3]={
          {'-1','-1','-1'},
          {'-1','-1','-1'},
          {'-1','-1','-1'}
            };
int win=0,turn=-1;
void IniBoard()
{
     cout<<"welcome to tic tac toe game";
     cout<<"t|__|__n";
     cout<<"t|__|__n";
     cout<<"t|__|__n";     
}
void DataInput()
{
     int x1,y1,x2,y2,chance=0;
     cout<<"who want to take turn first\n";
     cout<<"1-player 1\n";
     cout<<"2-Player 2\n";
     cout<<"enter your choice:";
     cin>>turn;

     while(chance<=9 || win=0)
     {
     if(turn==1)
     {
     cout<<"enter any row[1-3] and col[1-3]";
     cin>>x1>>y1;
     if(arr[x1-1][y1-1]=='-1')
     {arr[x-1][y-1]='x';turn=2;}
     else
     cout<<"you have entered an invalid choice";
     }
     if(turn==2)
     {
     if(turn==1)
     {
     cout<<"enter any row[1-3] and col[1-3]";
     cin>>x1>>y1;
     if(arr[x1-1][y1-1]=='-1')
     {arr[x-1][y-1]='x';turn=2;}
     else
     cout<<"you have entered an invalid choice";
     }
     
     chance++;
     }
     
}
void main()
{
     clrscr();
     IniBoard();
     getch();     
}
          
          
          
Comments: