X and O

I made an X and 0 game,but if one of the values of the array(X or O) is bigger than 3,the program says:X or O won.I wanna make something like a const(if a value has been introduced for X or O it cannot be modified),please post a solution for each of the question,or for atleast one of them...
#include<iostream>
using namespace std;
int main()
{ unsigned i,j,x,y,l,k,v[50],i2;
char XO[10][10];
for(i=1;i<=9;i++)
v[i]=0;
for(i=1;i<=3;i++)
for(j=1;j<=3;j++)
XO[i][j]='#';
for(i=1;i<=3;i++)
for(j=1;j<=3;j++)
{
if((i+j)%2==0)
{cout<<"Coordinates of X:"<<endl;
cin>>x;
cin>>y;
XO[x][y]='X';
for(l=1;l<=3;l++)
{ cout<<endl;
for(k=1;k<=3;k++)
cout<<" | "<<XO[l][k];
cout<<" | "<<endl<<endl;
}

cout<<endl;}
else
{cout<<"Coordinates of O:"<<endl;
cin>>x;
cin>>y;
XO[x][y]='O';
for(l=1;l<=3;l++)
{cout<<endl;
for(k=1;k<=3;k++)
cout<<" | "<<XO[l][k];
cout<<" | "<<endl<<endl;}
cout<<endl;}

for(l=1;l<=8;l++)
v[l]=0;
for(l=1;l<=3;l++)
for(k=1;k<=3;k++)
{if(x==y&&(l+k)%2==0)
v[1]++;
if(x==y&&(l+k)%2==1)
v[2]++;
if(x+y==4&&(l+k)%2==0)
v[3]++;
if(x+y==4&&(l+k)%2==1)
v[4]++;
if(XO[l][k]=='X')
v[5]++;
if(XO[l][k]=='O')
v[6]++;}
for(k=1;k<=3;k++)
for(l=1;l<=3;l++)
{if(XO[l][k]=='X')
v[7]++;
if(XO[l][k]=='O')
v[8]++;}
for(l=1;l<=8;l++)
if(v[l]==3&&l%2==1)
{cout<<"X has won"<<endl;
return 0;}
else if(v[l]==3&&l%2==0)
{cout<<"O has won"<<endl;
return 0;}
}
}
Your code looks unorganized and is hard to read.
What are you trying to achieve?
I try to inplement the "Rules" of x and o on the first or on the second diagonal,there must be 3 numbers(x==y,for the first diagonal and for the second x+y=n+1=3+1=4),and on the colomn or on the line there must be 3 numbers and if l+k is odd than we walk about X(1+1=2) and then if it is even(1+2=3) and so on..If one of the v is equal to 3,that means that one of the conditions is corect,if l is even(1) then we talk about the first number(X) and if it is not,then it is O.At school we make arrays i think from 2 weeks ago,i tried my best..sorry if it is not readable :) , i am not very organised..
I arranged it a little bit,at now it works,thanks
Topic archived. No new replies allowed.