tic tac toe

closed account (3UpjLyTq)
I have write this code to play tic tac toe but it does not like to work right. I need to check to see if there is a winner andto stop cheat and to run a loop but it does not want to enter the loop. I have not fig out how to stop the cheating part yet. that will come later. I have change it to a do loop form a while and for loop which did not run when I try them. It will not run agian it just stop for no reason. When I cout the array it has these Symbols in it place that are supposed to be numbers. When I use the if statments enter the place that I want an x to go it put them every on the broad. I can not even get the o to work becuase it does not want to loop. For the life of me i do not under stand why. I do not know why it is useing the symbols instead of the numbers. I think the reason why I get these symbols is becuase it is a string should I used ascii for putting in the data would that fix my problem. If so then how do I fix the loop problem. SO here is the code

#include <iostream>
#include <string>
#include <fstream>
using namespace std;


int main()
{
string x;
string o;
x="x";
o="o";
string player1;
string player2;
int t, y, v, f, u, z, b, c, w, r, q, l;
string matt[3][3];
cout << " This is a tic tac toe Game.\n" << " Have fun and enjoy.\n" << endl;
cout << " When entering the name of the player\n" << " USE ONLY ONE WORD NO SPACE ARE ALLOWED.\n"<< endl;
cout << " Enter the name of player one.\n" << endl;
getline(cin,player1);
cout << " Enter the name of player two.\n" << endl;
getline(cin,player2);
cout << " This is the Name of player one. \t" << player1 << endl;
cout << " This is the Name of player two. \t" << player2 << endl;
f=1;
u=2;
z=3;
b=4;
c=5;
w=6;
q=7;
r=8;
l=9;
matt[0][0]=f;
matt[0][1]=u;
matt[0][2]=z;
matt[1][0]=b;
matt[1][1]=c;
matt[1][2]=w;
matt[2][0]=q;
matt[2][1]=r;
matt[2][2]=l;

cout << matt[0][0] << "__________" << matt[0][1] << "__________" << matt[0][2] << endl;
cout << matt[1][0] << "__________" << matt[1][1] << "__________" << matt[1][2] << endl;
cout << matt[2][0] << "__________" << matt[2][1] << "__________" << matt[2][2] << endl;

do
{
y=1;
cout << matt[0][0] << "__________" << matt[0][1] << "__________" << matt[0][2] << endl;
cout << matt[1][0] << "__________" << matt[1][1] << "__________" << matt[1][2] << endl;
cout << matt[2][0] << "__________" << matt[2][1] << "__________" << matt[2][2] << endl;
cout << " Player " << player1 << " it is your turn enter a number.\n" << endl;
cin >> v;
if (v=1)
{
matt[0][0]=x;
}
if (v=2)
{
matt[0][1]=x;
}
if (v=3)
{
matt[0][2]=x;
}
if (v=4)
{
matt[1][0]=x;
}
if (v=5)
{
matt[1][1]=x;
}
if (v=6)
{
matt[1][2]=x;
}
if (v=7)
{
matt[2][0]=x;
}
if (v=8)
{
matt[2][1]=x;
}
if (v=9)
{
matt[2][2]=x;
}
cout << matt[0][0] << "__________" << matt[0][1] << "__________" << matt[0][2] << endl;
cout << matt[1][0] << "__________" << matt[1][1] << "__________" << matt[1][2] << endl;
cout << matt[2][0] << "__________" << matt[2][1] << "__________" << matt[2][2] << endl;
cout << " Player "<< player2 << " it is your turn enter a number. \n" << endl;
cin >> t;
if (t=1)
{
matt[0][0]=o;
}
if (t=2)
{
matt[0][1]=o;
}
if (t=3)
{
matt[0][2]=o;
}
if (t=4)
{
matt[1][0]=o;
}
if (t=5)
{
matt[1][1]=o;
}
if (t=6)
{
matt[1][2]=o;
}
if (t=7)
{
matt[2][0]=o;
}
if (t=8)
{
matt[2][1]=o;
}
if (t=9)
{
matt[2][2]=o;
}
break;
} while (y>=10);



if ( matt[0][0]== matt[0][1] && matt[0][1]==matt[0][2] && matt[0][0]==matt[0][2])
{
cout << " We have a winner" << endl;
}
if ( matt[1][0]== matt[1][1] && matt[1][1]==matt[1][2] && matt[1][0]==matt[1][2])
{
cout << " We have a winner" << endl;
}
if ( matt[2][0]== matt[2][1] && matt[2][1]==matt[2][2] && matt[2][0]==matt[2][2])
{
cout << " We have a winner" << endl;
}
if ( matt[0][0]== matt[1][0] && matt[1][0]==matt[2][0] && matt[0][0]==matt[2][0])
{
cout << " We have a winner" << endl;
}
if ( matt[0][1]== matt[1][1] && matt[1][1]==matt[2][1] && matt[0][1]==matt[2][1])
{
cout << " We have a winner" << endl;
}
if ( matt[0][2]== matt[1][2] && matt[1][2]==matt[2][2] && matt[0][2]==matt[2][2])
{
cout << " We have a winner" << endl;
}
if ( matt[0][0]== matt[1][1] && matt[1][1]==matt[2][2] && matt[0][0]==matt[2][2])
{
cout << " We have a winner" << endl;
}
if ( matt[2][0]== matt[1][1] && matt[1][1]==matt[0][2] && matt[2][0]==matt[0][2])
{
cout << " We have a winner" << endl;
}


return 0;
}


ANY help you give me would be greatly need thank you for your time.

 
if (v=1)


Assigns 1 to the variable v, then tests whether or not v is zero.
Topic archived. No new replies allowed.