help wid few things:
-exit function
-check if one wins
-cannot enter in an occupied place...
i would be thankful!
#include <iostream>
#include <string>
using namespace std;
int main()
{
string a = "1";
string b = "2";
string c = "3";
string d = "4";
string e = "5";
string f = "6";
string g = "7";
string h = "8";
string i = "9";
int a1=1;
int b1=2;
int c1=3;
int a2=4;
int b2=5;
int c2=6;
int a3=7;
int b3=8;
int c3=9;
int playerX;
int playerO;
int sum=0;
string x ="X";
string o = "O";
cout << "\t\tWelcome to tic-tac-toe!"<<endl;
cout << "\t\tThis is a two player game" << endl;
cout << endl;
cout << "For X to go first enter 1" <<endl;
cout << "For O to go first enter 2" <<endl;
while (sum <20)
{
int n;
cin >> n;
switch (n)
{
case 1 :
cout << "\n\t\t " << a << " | " << b << " | " << c << endl;
cout << "\t\t---+---+---"<< endl;
cout << "\t\t " << d << " | " << e << " | " << f << endl;
cout << "\t\t---+---+---"<< endl;
cout << "\t\t " << g << " | " << h << " | " << i << endl;
cout << "\nFor X: ";
cin >> playerX;
if (playerX == a1)
a = x;
else if (playerX == b1)
b = x;
else if (playerX == c1)
c = x;
else if (playerX == a2)
d = x;
else if (playerX == b2)
e = x;
else if (playerX == c2)
f = x;
else if (playerX == a3)
g = x;
else if (playerX == b3)
h = x;
else if (playerX == c3)
i = x;
cout << "\n\t\t " << a << " | " << b << " | " << c << endl;
cout << "\t\t---+---+---"<< endl;
cout << "\t\t " << d << " | " << e << " | " << f << endl;
cout << "\t\t---+---+---"<< endl;
cout << "\t\t " << g << " | " << h << " | " << i << endl;
cout << "For O: ";
cin >> playerO;
if (playerO == a1)
a = o;
else if (playerO == b1)
b = o;
else if (playerO == c1)
c = o;
else if (playerO == a2)
d = o;
else if (playerO == b2)
e = o;
else if (playerO == c2)
f = o;
else if (playerO == a3)
g = o;
else if (playerO == b3)
h = o;
else if (playerO == c3)
i = o;
cout << "\n\t\t " << a << " | " << b << " | " << c << endl;
cout << "\t\t---+---+---"<< endl;
cout << "\t\t " << d << " | " << e << " | " << f << endl;
cout << "\t\t---+---+---"<< endl;
cout << "\t\t " << g << " | " << h << " | " << i << endl;
break;
case 2:
cout << "\n\t\t " << a << " | " << b << " | " << c << endl;
cout << "\t\t---+---+---"<< endl;
cout << "\t\t " << d << " | " << e << " | " << f << endl;
cout << "\t\t---+---+---"<< endl;
cout << "\t\t " << g << " | " << h << " | " << i << endl;
cout << "\nFor O: ";
cin >> playerO;
if (playerO == a1)
a = o;
else if (playerO == b1)
b = o;
else if (playerO == c1)
c = o;
else if (playerO == a2)
d = o;
else if (playerO == b2)
e = o;
else if (playerO == c2)
f = o;
else if (playerO == a3)
g = o;
else if (playerO == b3)
h = o;
else if (playerO == c3)
i = o;
cout << "\n\t\t " << a << " | " << b << " | " << c << endl;
cout << "\t\t---+---+---"<< endl;
cout << "\t\t " << d << " | " << e << " | " << f << endl;
cout << "\t\t---+---+---"<< endl;
cout << "\t\t " << g << " | " << h << " | " << i << endl;
cout << "\nFor X: ";
cin >> playerX;
if (playerX == a1)
a = x;
else if (playerX == b1)
b = x;
else if (playerX == c1)
c = x;
else if (playerX == a2)
d = x;
else if (playerX == b2)
e = x;
else if (playerX == c2)
f = x;
else if (playerX == a3)
g = x;
else if (playerX == b3)
h = x;
else if (playerX == c3)
i = x;
cout << "\n\t\t " << a << " | " << b << " | " << c << endl;
cout << "\t\t---+---+---"<< endl;
cout << "\t\t " << d << " | " << e << " | " << f << endl;
cout << "\t\t---+---+---"<< endl;
cout << "\t\t " << g << " | " << h << " | " << i << endl;
break;
};
};
return 0;
}