can someone give me an opinion on how to improve my code? im trying to teach myself c++. btw, its tic tac toe
[code]
#include <iostream.h>
#include <stdlib.h>
char board[3][3];
void clearboard();
void showboard();
void getx();
void gety();
int checkboardx();
int checkboardy();
int main()
{
int loop=0;
clearboard();
showboard();
A:
getx();
loop++;
showboard();
if(checkboardx()==1)
{
cout<<"
*********
*X WINS!*
*********
\n";
system("PAUSE");
return 0;
}
if(loop==9)
{
cout<<"
*********
* TIE *
*********
\n";
system("PAUSE");
return 0;
}
gety();
loop++;
showboard();
if(checkboardy()==1)
{
cout<<"
*********
*O WINS!*
*********
\n";
system("PAUSE");
return 0;
}
goto A;
}
void clearboard()
{
int x,y;
for(x=0; x<3; x++)
{
for(y=0; y<3;y++)
{
board[x][y]='.';
}
}
}
void showboard()
{
int x,y,z;
y=0;
cout<<endl<<endl<<"Board Status: "<<endl;
cout<<"1 2 3"<<endl;
cout<<"-------"<<endl;
for(x=0; x<3; x++)
{
cout<<board[x][y]<<" ";
}
cout<<"| 1"<<endl;
y=1;
for(x=0; x<3; x++)
{
cout<<board[x][y]<<" ";
}
y=2;
cout<<"| 2"<<endl;
for(x=0; x<3; x++)
{
cout<<board[x][y]<<" ";
}
cout<<"| 3"<<endl<<endl<<endl;
}
void getx()
{
int x,y;
cout<<"
Place an X
-----------
Type the X coordinate: ";
cin>>x;
x=x-1;
cout<<"
Type the Y coordinate: ";
cin>>y;
y=y-1;
if(board[x][y]=='.')
{
board[x][y]='X';
}
else
{
cout<<"Already taken!\n";
getx();
}
system("CLS");
}
void gety()
{
int x,y;
cout<<"
Place a Y
---------
Type the X coordinate: ";
cin>>x;
x=x-1;
cout<<"
Type the Y coordinate: ";
cin>>y;
y=y-1;
if(board[x][y]=='.')
{
board[x][y]='O';
}
else
{
cout<<"Already taken!\n";
gety();
}
system("CLS");
}
int checkboardx()
{
if(board[0][0]=='X' && board[0][1]=='X' && board[0][2]=='X')
{
return 1;
}
if(board[1][0]=='X' && board[1][1]=='X' && board[1][2]=='X')
{
return 1;
}
if(board[2][0]=='X' && board[2][1]=='X' && board[2][2]=='X')
{
return 1;
}
if(board[0][0]=='X' && board[1][0]=='X' && board[2][0]=='X')
{
return 1;
}
if(board[0][1]=='X' && board[1][1]=='X' && board[2][1]=='X')
{
return 1;
}
if(board[0][2]=='X' && board[1][2]=='X' && board[2][2]=='X')
{
return 1;
}
if(board[0][0]=='X' && board[1][1]=='X' && board[2][2]=='X')
{
return 1;
}
if(board[2][0]=='X' && board[1][1]=='X' && board[0][2]=='X')
{
return 1;
}
return 0;
}
int checkboardy()
{
if(board[0][0]=='O' && board[0][1]=='O' && board[0][2]=='O')
{
return 1;
}
if(board[1][0]=='O' && board[1][1]=='O' && board[1][2]=='O')
{
return 1;
}
if(board[2][0]=='O' && board[2][1]=='O' && board[2][2]=='O')
{
return 1;
}
if(board[0][0]=='O' && board[1][0]=='O' && board[2][0]=='O')
{
return 1;
}
if(board[0][1]=='O' && board[1][1]=='O' && board[2][1]=='O')
{
return 1;
}
if(board[0][2]=='O' && board[1][2]=='O' && board[2][2]=='O')
{
return 1;
}
if(board[0][0]=='O' && board[1][1]=='O' && board[2][2]=='O')
{
return 1;
}
if(board[2][0]=='O' && board[1][1]=='O' && board[0][2]=='O')
{
return 1;
}
return 0;
}