how i create a tic tac program in c++, just with loops
and arrays. i just started the c++ two months ago.
Tic tac C++ programming.?
#include%26lt;iostream.h%26gt;
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 %26gt;%26gt; v; //MARKING
if (list[v-1]!='X' and list[v-1]!='O')
{
list[v-1]=pl;
}
else
{
cout %26lt;%26lt; "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%26lt;2; w++)
{
if (w==0)
{
p='X';
}
else{
p='O';
}
for (int z=0; z%26lt;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%26lt;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%26lt;9; x++) {
cout %26lt;%26lt; list[x];
if (x==2 or x==5 or x==8) {
cout %26lt;%26lt; "\n";
}
}
//END PRINTING OF THE VALUES
//system("PAUSE");
}
while (stop==false);
//End the while loop
GAME_END:;
cout %26lt;%26lt; p %26lt;%26lt; " wins!\n";
system("PAUSE");
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment