Post by Azan on Sept 27, 2005 19:30:26 GMT -5
Here it is.
#include<iostream.h>
int main() {
int stop=false;
char pl='X';
char p; //is used for checking when a game is won
int v; //value
char list[]="123456789\0"; //create our array that holds all the values
do { //start our while loop
//INPUT
cin >> v;
//MARKING
if (list[v-1]!='X' and list[v-1]!='O') {
list[v-1]=pl;
}
else {
cout << "That place is already taken.\n";
goto skip; //if its already taken skip the turn switch
}
if (pl=='X') {
pl='O';
}
else {
pl='X';
}
skip:;
//win checks
for (int w=0; w<2; w++){
if (w==0){
p='X';
}
else{
p='O';
}
for (int z=0; z<9; z=z+3) {
if (list[z]==p and list[z+1]==p and list[z+2]==p) {
stop=true;
goto GAME_END;
}
}
for (int z=0; z<3; z++) {
if (list[z]==p and list[z+3]==p and list[z+6]==p) {
stop=true;
goto GAME_END;
}
}
if (list[0]==p and list[4]==p and list[8]==p or list[2]==p and list[4]==p and list[6]==p){
goto GAME_END;
}
}
//PRINTING OF THE VALUES
for (int x=0; x<9; x++) {
cout << list[x];
if (x==2 or x==5 or x==8) {
cout << "\n";
}
}
//END PRINTING OF THE VALUES
//system("PAUSE");
} while (stop==false); //End the while loop
GAME_END:;
cout << p << " wins!\n";
system("PAUSE");
}