// Fix this program that works // Use welcome function that display the message in diffreent color // Use Draw function to diplay table in gree/yellow // Remove, add, any code that you believe is not useful #include #include using namespace std; char mat[3][3]; void table(); //function to print the table void welcome(); //function for welcome screen int main() { int i, j, m, n, sum = 0; char ch; welcome(); system("pause"); for (m = 0; m < 3; m++) for (n = 0; n < 3; n++) mat[m][n] ='W'; table(); while (sum < 10) { //================== for player 1 =================== cout << "Player 1 is X Choose the position : "; cout << "Row:"; cin >> i; cout << "Coloumn:"; cin >> j; //============== if position is wrong ============ for (; i > 3 || i < 1 || j>3 || j < 1 || ('x' == mat[i - 1][j - 1] || 'o' == mat[i - 1][j - 1]);) { cout << "Sorry!!!!wrong position, Choose the position again"; cout << "Row:"; cin >> i; cout << "Coloumn:"; cin >> j; } mat[i - 1][j - 1] = 'x'; sum++; //=============== to check if player 1 wins or not=================== if (mat[0][0] == 'x' && mat[0][0] == mat[0][1] && mat[0][0] == mat[0][2]) { table(); cout << "Player 1 wins…….!!!"; cout << "You have played Great…..!!!"; // break; } if (mat[1][0] == 'x' && mat[1][0] == mat[1][1] && mat[1][0] == mat[1][2]) { table(); cout << "Player 1 wins…….!!!"; cout << "You have played Great…..!!!"<> i; cout << "Coloumn:"; cin >> j; //if position is wrong for (; i > 3 || i < 1 || j>3 || j < 1 || ('x' == mat[i - 1][j - 1] || 'o' == mat[i - 1][j - 1]);) { cout << "Sorry!!!!wrong position, Choose the position again" << endl; cout << "Row:"<> i; cout << "Coloumn:" << endl; cin >> j; } mat[i - 1][j - 1] = 'o'; sum++; table();
// Fix this program that works
// Use welcome function that display the message in diffreent color
// Use Draw function to diplay table in gree/yellow
// Remove, add, any code that you believe is not useful
#include <iostream>
#include <windows.h>
using namespace std;
char mat[3][3];
void table(); //function to print the table
void welcome(); //function for welcome screen
int main()
{
int i, j, m, n, sum = 0;
char ch;
welcome();
system("pause");
for (m = 0; m < 3; m++)
for (n = 0; n < 3; n++)
mat[m][n] ='W';
table();
while (sum < 10)
{
//================== for player 1 ===================
cout << "Player 1 is X Choose the position : ";
cout << "Row:";
cin >> i;
cout << "Coloumn:";
cin >> j;
//============== if position is wrong ============
for (; i > 3 || i < 1 || j>3 || j < 1 || ('x' == mat[i - 1][j - 1] || 'o' == mat[i - 1][j - 1]);)
{
cout << "Sorry!!!!wrong position, Choose the position again";
cout << "Row:";
cin >> i;
cout << "Coloumn:";
cin >> j;
}
mat[i - 1][j - 1] = 'x';
sum++;
//=============== to check if player 1 wins or not===================
if (mat[0][0] == 'x' && mat[0][0] == mat[0][1] && mat[0][0] == mat[0][2])
{
table();
cout << "Player 1 wins…….!!!";
cout << "You have played Great…..!!!";
//
break;
}
if (mat[1][0] == 'x' && mat[1][0] == mat[1][1] && mat[1][0] == mat[1][2])
{
table();
cout << "Player 1 wins…….!!!";
cout << "You have played Great…..!!!"<<endl;
break;
}
if (mat[2][0] == 'x' && mat[2][0] == mat[2][1] && mat[2][0] == mat[2][2])
{
table();
cout << "Player 1 wins…….!!!";
cout << "You have played Great…..!!!"<<endl;
break;
}
if (mat[0][0] == 'x' && mat[0][0] == mat[1][0] && mat[0][0] == mat[2][0])
{
table();
cout << "Player 1 wins…….!!!";
cout << "You have played Great…..!!!";
break;
}
if (mat[0][1] == 'x' && mat[0][1] == mat[1][1] && mat[0][1] == mat[2][1])
{
table();
cout << "Player 1 wins…….!!!";
cout << "You have played Great…..!!!";
break;
}
if (mat[0][2] == 'x' && mat[0][2] == mat[1][2] && mat[0][2] == mat[2][2])
{
table();
cout << "Player 1 wins…….!!!"<<endl;
cout << "You have played Great…..!!!"<<endl;
break;
}
if (mat[0][0] == 'x' && mat[0][0] == mat[1][1] && mat[0][0] == mat[2][2])
{
table();
cout << "Player 1 wins…….!!!"<<endl;
cout << "You have played Great…..!!!"<<endl;
break;
}
if (mat[0][2] == 'x' && mat[0][2] == mat[1][1] && mat[0][0] == mat[2][0])
{
table();
cout << "Player 1 wins…….!!!"<<endl;
cout << "You have played Great…..!!!"<<endl;
break;
}
if (sum == 9) //to check the chances
{
table();
cout << "The game is over…….no one wins…HaHaHa…..!!!";
break;
}
//for player 2
cout << "Player 2 is’o’nChoose the position : " << endl;
cout << "Row:";
cin >> i;
cout << "Coloumn:";
cin >> j;
//if position is wrong
for (; i > 3 || i < 1 || j>3 || j < 1 || ('x' == mat[i - 1][j - 1] || 'o' == mat[i - 1][j - 1]);)
{
cout << "Sorry!!!!wrong position, Choose the position again" << endl;
cout << "Row:"<<endl;
cin >> i;
cout << "Coloumn:" << endl;
cin >> j;
}
mat[i - 1][j - 1] = 'o';
sum++;
table();
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images