SlideShare a Scribd company logo
Please follow the data :
1) For Line 23 :
In the IF - Condition you are just checking the cells of the grid at positions 0 and 1. But I
suppose you would like to check if both the cells are having the character value 'x'. So to
achieve this you need to replace the code with
if(grid[0] == grid[1] == 'x')
2) For Line 29 :
The error is that the function has been define before the error line and the loop has not been
closed so pplace a closing brackets for the loop before the line starting with bool tie()
3) For Line 37 :
The above change should also resolve this as the scope of the main function isnt predefined.
4) For Line 69 :
Remove the excess bracket at the end of the code.
Even after replacing these I suppose your code would not work as the input has not been defined
from where and how thw user can get the data to the code. So to avoid this I am placing my
code.
Please follow the code and comments for descripiton :
CODE :
#include
using namespace std;
int checkWin( char[]); // rewuired variables
void grid( char[]);
int main()
{
char cell[10] = {'o','1','2','3','4','5','6','7','8','9'}; // placing the cell names
int player = 1,i,choice; // initialisations
char symbol;
do // looping to get the player choices
{
grid(cell);
if(player%2==1) { // checking for the player
player=1;
} else {
player=2;
}
// player 2 is the computer
if(player==2) // if is a player 2
{
cout << "Player " << player<> choice;
symbol='X';
if (choice == 1 && cell[1] == '1') {
cell[1] = symbol;
}
else if (choice == 2 && cell[2] == '2') {
cell[2] = symbol;
}
else if (choice == 3 && cell[3] == '3') {
cell[3] = symbol;
}
else if (choice == 4 && cell[4] == '4') {
cell[4] = symbol;
}
else if (choice == 5 && cell[5] == '5') {
cell[5] = symbol;
}
else if (choice == 6 && cell[6] == '6') {
cell[6] = symbol;
}
else if (choice == 7 && cell[7] == '7') {
cell[7] = symbol;
}
else if (choice == 8 && cell[8] == '8') {
cell[8] = symbol;
}
else if (choice == 9 && cell[9] == '9') {
cell[9] = symbol;
} else {
cout<<"Invalid move..!!!"<< endl;
player--;
exit(0);
}
i=checkWin(cell);
player++;
}
} while(i==-1);
grid(cell);
if(i==1) {
cout<<"Congratulations!  Player "<<--player<<" won the Game..!!";
} else {
cout<<" OOPS..!!!! The Game has been tie..!!";
}
exit(0);
return 0;
}
void grid(char cell[]) // printing the grid everytime the user has placed the symbol
{
system("cls");
cout << "  tTic Tac Toe Game  ";
cout << "Player 1 (X) - Player 2 (O)" << endl << endl;
cout << endl;
cout << " | | " << endl;
cout << " " << cell[1] << " | " << cell[2] << " | " << cell[3] << endl;
cout << "_____|_____|_____" << endl;
cout << " | | " << endl;
cout << " " << cell[4] << " | " << cell[5] << " | " << cell[6] << endl;
cout << "_____|_____|_____" << endl;
cout << " | | " << endl;
cout << " " << cell[7] << " | " << cell[8] << " | " << cell[9] << endl;
cout << " | | " << endl << endl;
}
int checkWin(char cell[])// checking for the win condition
{
if (cell[1] == cell[2] && cell[2] == cell[3]) {
return 1;
}
else if (cell[4] == cell[5] && cell[5] == cell[6]) {
return 1;
}
else if (cell[7] == cell[8] && cell[8] == cell[9]) {
return 1;
}
else if (cell[1] == cell[4] && cell[4] == cell[7]) {
return 1;
}
else if (cell[2] == cell[5] && cell[5] == cell[8]) {
return 1;
}
else if (cell[3] == cell[6] && cell[6] == cell[9]) {
return 1;
}
else if (cell[1] == cell[5] && cell[5] == cell[9]) {
return 1;
}
else if (cell[3] == cell[5] && cell[5] == cell[7]) {
return 1;
}
else if (cell[1] != '1' && cell[2] != '2' && cell[3] != '3'
&& cell[4] != '4' && cell[5] != '5' && cell[6] != '6'
&& cell[7] != '7' && cell[8] != '8' && cell[9] != '9') {
return 0;
}
else {
return -1;
}
}
OUTPUT :
1) For a Tie Game Case :
Tic Tac Toe Game
Player 1 (X) - Player 2 (O)
| |
1 | 2 | 3
_____|_____|_____
| |
4 | 5 | 6
_____|_____|_____
| |
7 | 8 | 9
| |
Player 1, Please enter the grid number to place the symbol :
7
Tic Tac Toe Game
Player 1 (X) - Player 2 (O)
| |
1 | 2 | 3
_____|_____|_____
| |
4 | 5 | 6
_____|_____|_____
| |
X | 8 | 9
| |
Player 2
Press Enter for the Computer Turn..!!
Tic Tac Toe Game
Player 1 (X) - Player 2 (O)
| |
O | 2 | 3
_____|_____|_____
| |
4 | 5 | 6
_____|_____|_____
| |
X | 8 | 9
| |
Tic Tac Toe Game
Player 1 (X) - Player 2 (O)
| |
O | 2 | 3
_____|_____|_____
| |
4 | 5 | 6
_____|_____|_____
| |
X | 8 | 9
| |
Player 1, Please enter the grid number to place the symbol : 5
Tic Tac Toe Game
Player 1 (X) - Player 2 (O)
| |
O | 2 | 3
_____|_____|_____
| |
4 | X | 6
_____|_____|_____
| |
X | 8 | 9
| |
Player 2
Press Enter for the Computer Turn..!!
Tic Tac Toe Game
Player 1 (X) - Player 2 (O)
| |
O | 2 | O
_____|_____|_____
| |
4 | X | 6
_____|_____|_____
| |
X | 8 | 9
| |
Tic Tac Toe Game
Player 1 (X) - Player 2 (O)
| |
O | 2 | O
_____|_____|_____
| |
4 | X | 6
_____|_____|_____
| |
X | 8 | 9
| |
Player 1, Please enter the grid number to place the symbol : 2
Tic Tac Toe Game
Player 1 (X) - Player 2 (O)
| |
O | X | O
_____|_____|_____
| |
4 | X | 6
_____|_____|_____
| |
X | 8 | 9
| |
Player 2
Press Enter for the Computer Turn..!!
Tic Tac Toe Game
Player 1 (X) - Player 2 (O)
| |
O | X | O
_____|_____|_____
| |
4 | X | O
_____|_____|_____
| |
X | 8 | 9
| |
Tic Tac Toe Game
Player 1 (X) - Player 2 (O)
| |
O | X | O
_____|_____|_____
| |
4 | X | O
_____|_____|_____
| |
X | 8 | 9
| |
Player 1, Please enter the grid number to place the symbol : 4
Tic Tac Toe Game
Player 1 (X) - Player 2 (O)
| |
O | X | O
_____|_____|_____
| |
X | X | O
_____|_____|_____
| |
X | 8 | 9
| |
Player 2
Press Enter for the Computer Turn..!!
Tic Tac Toe Game
Player 1 (X) - Player 2 (O)
| |
O | X | O
_____|_____|_____
| |
X | X | O
_____|_____|_____
| |
X | O | 9
| |
Tic Tac Toe Game
Player 1 (X) - Player 2 (O)
| |
O | X | O
_____|_____|_____
| |
X | X | O
_____|_____|_____
| |
X | O | 9
| |
Player 1, Please enter the grid number to place the symbol : 9
Tic Tac Toe Game
Player 1 (X) - Player 2 (O)
| |
O | X | O
_____|_____|_____
| |
X | X | O
_____|_____|_____
| |
X | O | X
| |
OOPS..!!!!
The Game has been tie..!!
2) For Win Case :
Tic Tac Toe Game
Player 1 (X) - Player 2 (O)
| |
1 | 2 | 3
_____|_____|_____
| |
4 | 5 | 6
_____|_____|_____
| |
7 | 8 | 9
| |
Player 1, Please enter the grid number to place the symbol : 1
Tic Tac Toe Game
Player 1 (X) - Player 2 (O)
| |
X | 2 | 3
_____|_____|_____
| |
4 | 5 | 6
_____|_____|_____
| |
7 | 8 | 9
| |
Player 2
Press Enter for the Computer Turn..!!
Tic Tac Toe Game
Player 1 (X) - Player 2 (O)
| |
X | 2 | 3
_____|_____|_____
| |
4 | 5 | 6
_____|_____|_____
| |
O | 8 | 9
| |
Tic Tac Toe Game
Player 1 (X) - Player 2 (O)
| |
X | 2 | 3
_____|_____|_____
| |
4 | 5 | 6
_____|_____|_____
| |
O | 8 | 9
| |
Player 1, Please enter the grid number to place the symbol : 2
Tic Tac Toe Game
Player 1 (X) - Player 2 (O)
| |
X | X | 3
_____|_____|_____
| |
4 | 5 | 6
_____|_____|_____
| |
O | 8 | 9
| |
Player 2
Press Enter for the Computer Turn..!!
Tic Tac Toe Game
Player 1 (X) - Player 2 (O)
| |
X | X | 3
_____|_____|_____
| |
4 | O | 6
_____|_____|_____
| |
O | 8 | 9
| |
Tic Tac Toe Game
Player 1 (X) - Player 2 (O)
| |
X | X | 3
_____|_____|_____
| |
4 | O | 6
_____|_____|_____
| |
O | 8 | 9
| |
Player 1, Please enter the grid number to place the symbol : 3
Tic Tac Toe Game
Player 1 (X) - Player 2 (O)
| |
X | X | X
_____|_____|_____
| |
4 | O | 6
_____|_____|_____
| |
O | 8 | 9
| |
Congratulations!
Player 1 won the Game..!!
Hope this is helpful.
Solution
Please follow the data :
1) For Line 23 :
In the IF - Condition you are just checking the cells of the grid at positions 0 and 1. But I
suppose you would like to check if both the cells are having the character value 'x'. So to
achieve this you need to replace the code with
if(grid[0] == grid[1] == 'x')
2) For Line 29 :
The error is that the function has been define before the error line and the loop has not been
closed so pplace a closing brackets for the loop before the line starting with bool tie()
3) For Line 37 :
The above change should also resolve this as the scope of the main function isnt predefined.
4) For Line 69 :
Remove the excess bracket at the end of the code.
Even after replacing these I suppose your code would not work as the input has not been defined
from where and how thw user can get the data to the code. So to avoid this I am placing my
code.
Please follow the code and comments for descripiton :
CODE :
#include
using namespace std;
int checkWin( char[]); // rewuired variables
void grid( char[]);
int main()
{
char cell[10] = {'o','1','2','3','4','5','6','7','8','9'}; // placing the cell names
int player = 1,i,choice; // initialisations
char symbol;
do // looping to get the player choices
{
grid(cell);
if(player%2==1) { // checking for the player
player=1;
} else {
player=2;
}
// player 2 is the computer
if(player==2) // if is a player 2
{
cout << "Player " << player<> choice;
symbol='X';
if (choice == 1 && cell[1] == '1') {
cell[1] = symbol;
}
else if (choice == 2 && cell[2] == '2') {
cell[2] = symbol;
}
else if (choice == 3 && cell[3] == '3') {
cell[3] = symbol;
}
else if (choice == 4 && cell[4] == '4') {
cell[4] = symbol;
}
else if (choice == 5 && cell[5] == '5') {
cell[5] = symbol;
}
else if (choice == 6 && cell[6] == '6') {
cell[6] = symbol;
}
else if (choice == 7 && cell[7] == '7') {
cell[7] = symbol;
}
else if (choice == 8 && cell[8] == '8') {
cell[8] = symbol;
}
else if (choice == 9 && cell[9] == '9') {
cell[9] = symbol;
} else {
cout<<"Invalid move..!!!"<< endl;
player--;
exit(0);
}
i=checkWin(cell);
player++;
}
} while(i==-1);
grid(cell);
if(i==1) {
cout<<"Congratulations!  Player "<<--player<<" won the Game..!!";
} else {
cout<<" OOPS..!!!! The Game has been tie..!!";
}
exit(0);
return 0;
}
void grid(char cell[]) // printing the grid everytime the user has placed the symbol
{
system("cls");
cout << "  tTic Tac Toe Game  ";
cout << "Player 1 (X) - Player 2 (O)" << endl << endl;
cout << endl;
cout << " | | " << endl;
cout << " " << cell[1] << " | " << cell[2] << " | " << cell[3] << endl;
cout << "_____|_____|_____" << endl;
cout << " | | " << endl;
cout << " " << cell[4] << " | " << cell[5] << " | " << cell[6] << endl;
cout << "_____|_____|_____" << endl;
cout << " | | " << endl;
cout << " " << cell[7] << " | " << cell[8] << " | " << cell[9] << endl;
cout << " | | " << endl << endl;
}
int checkWin(char cell[])// checking for the win condition
{
if (cell[1] == cell[2] && cell[2] == cell[3]) {
return 1;
}
else if (cell[4] == cell[5] && cell[5] == cell[6]) {
return 1;
}
else if (cell[7] == cell[8] && cell[8] == cell[9]) {
return 1;
}
else if (cell[1] == cell[4] && cell[4] == cell[7]) {
return 1;
}
else if (cell[2] == cell[5] && cell[5] == cell[8]) {
return 1;
}
else if (cell[3] == cell[6] && cell[6] == cell[9]) {
return 1;
}
else if (cell[1] == cell[5] && cell[5] == cell[9]) {
return 1;
}
else if (cell[3] == cell[5] && cell[5] == cell[7]) {
return 1;
}
else if (cell[1] != '1' && cell[2] != '2' && cell[3] != '3'
&& cell[4] != '4' && cell[5] != '5' && cell[6] != '6'
&& cell[7] != '7' && cell[8] != '8' && cell[9] != '9') {
return 0;
}
else {
return -1;
}
}
OUTPUT :
1) For a Tie Game Case :
Tic Tac Toe Game
Player 1 (X) - Player 2 (O)
| |
1 | 2 | 3
_____|_____|_____
| |
4 | 5 | 6
_____|_____|_____
| |
7 | 8 | 9
| |
Player 1, Please enter the grid number to place the symbol :
7
Tic Tac Toe Game
Player 1 (X) - Player 2 (O)
| |
1 | 2 | 3
_____|_____|_____
| |
4 | 5 | 6
_____|_____|_____
| |
X | 8 | 9
| |
Player 2
Press Enter for the Computer Turn..!!
Tic Tac Toe Game
Player 1 (X) - Player 2 (O)
| |
O | 2 | 3
_____|_____|_____
| |
4 | 5 | 6
_____|_____|_____
| |
X | 8 | 9
| |
Tic Tac Toe Game
Player 1 (X) - Player 2 (O)
| |
O | 2 | 3
_____|_____|_____
| |
4 | 5 | 6
_____|_____|_____
| |
X | 8 | 9
| |
Player 1, Please enter the grid number to place the symbol : 5
Tic Tac Toe Game
Player 1 (X) - Player 2 (O)
| |
O | 2 | 3
_____|_____|_____
| |
4 | X | 6
_____|_____|_____
| |
X | 8 | 9
| |
Player 2
Press Enter for the Computer Turn..!!
Tic Tac Toe Game
Player 1 (X) - Player 2 (O)
| |
O | 2 | O
_____|_____|_____
| |
4 | X | 6
_____|_____|_____
| |
X | 8 | 9
| |
Tic Tac Toe Game
Player 1 (X) - Player 2 (O)
| |
O | 2 | O
_____|_____|_____
| |
4 | X | 6
_____|_____|_____
| |
X | 8 | 9
| |
Player 1, Please enter the grid number to place the symbol : 2
Tic Tac Toe Game
Player 1 (X) - Player 2 (O)
| |
O | X | O
_____|_____|_____
| |
4 | X | 6
_____|_____|_____
| |
X | 8 | 9
| |
Player 2
Press Enter for the Computer Turn..!!
Tic Tac Toe Game
Player 1 (X) - Player 2 (O)
| |
O | X | O
_____|_____|_____
| |
4 | X | O
_____|_____|_____
| |
X | 8 | 9
| |
Tic Tac Toe Game
Player 1 (X) - Player 2 (O)
| |
O | X | O
_____|_____|_____
| |
4 | X | O
_____|_____|_____
| |
X | 8 | 9
| |
Player 1, Please enter the grid number to place the symbol : 4
Tic Tac Toe Game
Player 1 (X) - Player 2 (O)
| |
O | X | O
_____|_____|_____
| |
X | X | O
_____|_____|_____
| |
X | 8 | 9
| |
Player 2
Press Enter for the Computer Turn..!!
Tic Tac Toe Game
Player 1 (X) - Player 2 (O)
| |
O | X | O
_____|_____|_____
| |
X | X | O
_____|_____|_____
| |
X | O | 9
| |
Tic Tac Toe Game
Player 1 (X) - Player 2 (O)
| |
O | X | O
_____|_____|_____
| |
X | X | O
_____|_____|_____
| |
X | O | 9
| |
Player 1, Please enter the grid number to place the symbol : 9
Tic Tac Toe Game
Player 1 (X) - Player 2 (O)
| |
O | X | O
_____|_____|_____
| |
X | X | O
_____|_____|_____
| |
X | O | X
| |
OOPS..!!!!
The Game has been tie..!!
2) For Win Case :
Tic Tac Toe Game
Player 1 (X) - Player 2 (O)
| |
1 | 2 | 3
_____|_____|_____
| |
4 | 5 | 6
_____|_____|_____
| |
7 | 8 | 9
| |
Player 1, Please enter the grid number to place the symbol : 1
Tic Tac Toe Game
Player 1 (X) - Player 2 (O)
| |
X | 2 | 3
_____|_____|_____
| |
4 | 5 | 6
_____|_____|_____
| |
7 | 8 | 9
| |
Player 2
Press Enter for the Computer Turn..!!
Tic Tac Toe Game
Player 1 (X) - Player 2 (O)
| |
X | 2 | 3
_____|_____|_____
| |
4 | 5 | 6
_____|_____|_____
| |
O | 8 | 9
| |
Tic Tac Toe Game
Player 1 (X) - Player 2 (O)
| |
X | 2 | 3
_____|_____|_____
| |
4 | 5 | 6
_____|_____|_____
| |
O | 8 | 9
| |
Player 1, Please enter the grid number to place the symbol : 2
Tic Tac Toe Game
Player 1 (X) - Player 2 (O)
| |
X | X | 3
_____|_____|_____
| |
4 | 5 | 6
_____|_____|_____
| |
O | 8 | 9
| |
Player 2
Press Enter for the Computer Turn..!!
Tic Tac Toe Game
Player 1 (X) - Player 2 (O)
| |
X | X | 3
_____|_____|_____
| |
4 | O | 6
_____|_____|_____
| |
O | 8 | 9
| |
Tic Tac Toe Game
Player 1 (X) - Player 2 (O)
| |
X | X | 3
_____|_____|_____
| |
4 | O | 6
_____|_____|_____
| |
O | 8 | 9
| |
Player 1, Please enter the grid number to place the symbol : 3
Tic Tac Toe Game
Player 1 (X) - Player 2 (O)
| |
X | X | X
_____|_____|_____
| |
4 | O | 6
_____|_____|_____
| |
O | 8 | 9
| |
Congratulations!
Player 1 won the Game..!!
Hope this is helpful.

More Related Content

Similar to Please follow the data 1) For Line 23 In the IF - Condition yo.pdf

The following is my code for a connectn program. When I run my code .pdf
The following is my code for a connectn program. When I run my code .pdfThe following is my code for a connectn program. When I run my code .pdf
The following is my code for a connectn program. When I run my code .pdf
eyelineoptics
 
Ludo game using c++ with documentation
Ludo game using c++ with documentation Ludo game using c++ with documentation
Ludo game using c++ with documentation
Mauryasuraj98
 
Objectives Create a Java program using programming fundamentals (fi.docx
Objectives Create a Java program using programming fundamentals (fi.docxObjectives Create a Java program using programming fundamentals (fi.docx
Objectives Create a Java program using programming fundamentals (fi.docx
amit657720
 
TIC-TAC-TOE IN C
TIC-TAC-TOE IN CTIC-TAC-TOE IN C
TIC-TAC-TOE IN C
IRJET Journal
 
0-miniproject sem 4 review 1(1)(2).pptx
0-miniproject sem 4 review 1(1)(2).pptx0-miniproject sem 4 review 1(1)(2).pptx
0-miniproject sem 4 review 1(1)(2).pptx
AhishektttPhm
 
C++You will design a program to play a simplified version of war, .pdf
C++You will design a program to play a simplified version of war, .pdfC++You will design a program to play a simplified version of war, .pdf
C++You will design a program to play a simplified version of war, .pdf
ezzi97
 
Here is the code for youimport java.util.Scanner; import java.u.pdf
Here is the code for youimport java.util.Scanner; import java.u.pdfHere is the code for youimport java.util.Scanner; import java.u.pdf
Here is the code for youimport java.util.Scanner; import java.u.pdf
anithareadymade
 
package com.tictactoe; public class Main {public void play() {.pdf
package com.tictactoe; public class Main {public void play() {.pdfpackage com.tictactoe; public class Main {public void play() {.pdf
package com.tictactoe; public class Main {public void play() {.pdf
info430661
 
201707 CSE110 Lecture 13
201707 CSE110 Lecture 13   201707 CSE110 Lecture 13
201707 CSE110 Lecture 13
Javier Gonzalez-Sanchez
 
Please help with this. program must be written in C# .. All of the g.pdf
Please help with this. program must be written in C# .. All of the g.pdfPlease help with this. program must be written in C# .. All of the g.pdf
Please help with this. program must be written in C# .. All of the g.pdf
manjan6
 
Write a program in java in which you will build the“Sink theShipsGam.pdf
Write a program in java in which you will build the“Sink theShipsGam.pdfWrite a program in java in which you will build the“Sink theShipsGam.pdf
Write a program in java in which you will build the“Sink theShipsGam.pdf
archanenterprises
 
You will write a multi-interface version of the well-known concentra.pdf
You will write a multi-interface version of the well-known concentra.pdfYou will write a multi-interface version of the well-known concentra.pdf
You will write a multi-interface version of the well-known concentra.pdf
FashionColZone
 
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
ssuserd6b1fd
 
Introduction to cpp (c++)
Introduction to cpp (c++)Introduction to cpp (c++)
Introduction to cpp (c++)
Arun Umrao
 
The Ring programming language version 1.7 book - Part 64 of 196
The Ring programming language version 1.7 book - Part 64 of 196The Ring programming language version 1.7 book - Part 64 of 196
The Ring programming language version 1.7 book - Part 64 of 196
Mahmoud Samir Fayed
 
Oct27
Oct27Oct27
Oct27
Tak Lee
 

Similar to Please follow the data 1) For Line 23 In the IF - Condition yo.pdf (17)

The following is my code for a connectn program. When I run my code .pdf
The following is my code for a connectn program. When I run my code .pdfThe following is my code for a connectn program. When I run my code .pdf
The following is my code for a connectn program. When I run my code .pdf
 
Ludo game using c++ with documentation
Ludo game using c++ with documentation Ludo game using c++ with documentation
Ludo game using c++ with documentation
 
Objectives Create a Java program using programming fundamentals (fi.docx
Objectives Create a Java program using programming fundamentals (fi.docxObjectives Create a Java program using programming fundamentals (fi.docx
Objectives Create a Java program using programming fundamentals (fi.docx
 
TIC-TAC-TOE IN C
TIC-TAC-TOE IN CTIC-TAC-TOE IN C
TIC-TAC-TOE IN C
 
0-miniproject sem 4 review 1(1)(2).pptx
0-miniproject sem 4 review 1(1)(2).pptx0-miniproject sem 4 review 1(1)(2).pptx
0-miniproject sem 4 review 1(1)(2).pptx
 
C++You will design a program to play a simplified version of war, .pdf
C++You will design a program to play a simplified version of war, .pdfC++You will design a program to play a simplified version of war, .pdf
C++You will design a program to play a simplified version of war, .pdf
 
Here is the code for youimport java.util.Scanner; import java.u.pdf
Here is the code for youimport java.util.Scanner; import java.u.pdfHere is the code for youimport java.util.Scanner; import java.u.pdf
Here is the code for youimport java.util.Scanner; import java.u.pdf
 
package com.tictactoe; public class Main {public void play() {.pdf
package com.tictactoe; public class Main {public void play() {.pdfpackage com.tictactoe; public class Main {public void play() {.pdf
package com.tictactoe; public class Main {public void play() {.pdf
 
201707 CSE110 Lecture 13
201707 CSE110 Lecture 13   201707 CSE110 Lecture 13
201707 CSE110 Lecture 13
 
Please help with this. program must be written in C# .. All of the g.pdf
Please help with this. program must be written in C# .. All of the g.pdfPlease help with this. program must be written in C# .. All of the g.pdf
Please help with this. program must be written in C# .. All of the g.pdf
 
Write a program in java in which you will build the“Sink theShipsGam.pdf
Write a program in java in which you will build the“Sink theShipsGam.pdfWrite a program in java in which you will build the“Sink theShipsGam.pdf
Write a program in java in which you will build the“Sink theShipsGam.pdf
 
You will write a multi-interface version of the well-known concentra.pdf
You will write a multi-interface version of the well-known concentra.pdfYou will write a multi-interface version of the well-known concentra.pdf
You will write a multi-interface version of the well-known concentra.pdf
 
RandomGuessingGame
RandomGuessingGameRandomGuessingGame
RandomGuessingGame
 
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
 
Introduction to cpp (c++)
Introduction to cpp (c++)Introduction to cpp (c++)
Introduction to cpp (c++)
 
The Ring programming language version 1.7 book - Part 64 of 196
The Ring programming language version 1.7 book - Part 64 of 196The Ring programming language version 1.7 book - Part 64 of 196
The Ring programming language version 1.7 book - Part 64 of 196
 
Oct27
Oct27Oct27
Oct27
 

More from info382133

1.) Main characteristics of Haloarchaea are as followsHalophiles .pdf
1.) Main characteristics of Haloarchaea are as followsHalophiles .pdf1.) Main characteristics of Haloarchaea are as followsHalophiles .pdf
1.) Main characteristics of Haloarchaea are as followsHalophiles .pdf
info382133
 
1. The three bacteria that may be implicated in the given case are S.pdf
1. The three bacteria that may be implicated in the given case are S.pdf1. The three bacteria that may be implicated in the given case are S.pdf
1. The three bacteria that may be implicated in the given case are S.pdf
info382133
 
1. Pros and Cons of IP CCTVNew threats are introduced to the secu.pdf
1. Pros and Cons of IP CCTVNew threats are introduced to the secu.pdf1. Pros and Cons of IP CCTVNew threats are introduced to the secu.pdf
1. Pros and Cons of IP CCTVNew threats are introduced to the secu.pdf
info382133
 
1. Activation of Vit. D involves Kidney and Liver and liver is part .pdf
1. Activation of Vit. D involves Kidney and Liver and liver is part .pdf1. Activation of Vit. D involves Kidney and Liver and liver is part .pdf
1. Activation of Vit. D involves Kidney and Liver and liver is part .pdf
info382133
 
Rf = (distance the spot traveled)L there are fou.pdf
                     Rf = (distance the spot traveled)L there are fou.pdf                     Rf = (distance the spot traveled)L there are fou.pdf
Rf = (distance the spot traveled)L there are fou.pdf
info382133
 
No. Since sodium chloride is an ionic compound, i.pdf
                     No. Since sodium chloride is an ionic compound, i.pdf                     No. Since sodium chloride is an ionic compound, i.pdf
No. Since sodium chloride is an ionic compound, i.pdf
info382133
 
Nacl is highly ionic in nature. where as CaO is s.pdf
                     Nacl is highly ionic in nature. where as CaO is s.pdf                     Nacl is highly ionic in nature. where as CaO is s.pdf
Nacl is highly ionic in nature. where as CaO is s.pdf
info382133
 
it is reduced as it accepts e- and goes from 0 to.pdf
                     it is reduced as it accepts e- and goes from 0 to.pdf                     it is reduced as it accepts e- and goes from 0 to.pdf
it is reduced as it accepts e- and goes from 0 to.pdf
info382133
 
Iodine test is used to see if a compound has star.pdf
                     Iodine test is used to see if a compound has star.pdf                     Iodine test is used to see if a compound has star.pdf
Iodine test is used to see if a compound has star.pdf
info382133
 
I have no clue! .pdf
                     I have no clue!                                  .pdf                     I have no clue!                                  .pdf
I have no clue! .pdf
info382133
 
C only III is major product .pdf
                     C only III is major product                      .pdf                     C only III is major product                      .pdf
C only III is major product .pdf
info382133
 
Borane-THF is flammable and highly reactive with .pdf
                     Borane-THF is flammable and highly reactive with .pdf                     Borane-THF is flammable and highly reactive with .pdf
Borane-THF is flammable and highly reactive with .pdf
info382133
 
Ubiquity Internet is available everywhere namely at home, at work v.pdf
Ubiquity Internet is available everywhere namely at home, at work v.pdfUbiquity Internet is available everywhere namely at home, at work v.pdf
Ubiquity Internet is available everywhere namely at home, at work v.pdf
info382133
 
Water is the most used resource in our day to day life . When the wa.pdf
Water is the most used resource in our day to day life . When the wa.pdfWater is the most used resource in our day to day life . When the wa.pdf
Water is the most used resource in our day to day life . When the wa.pdf
info382133
 
The initiation of the sporulation of the bacteria is a complex cellu.pdf
The initiation of the sporulation of the bacteria is a complex cellu.pdfThe initiation of the sporulation of the bacteria is a complex cellu.pdf
The initiation of the sporulation of the bacteria is a complex cellu.pdf
info382133
 
The emissivity of a given surface is the measure of its ability to e.pdf
The emissivity of a given surface is the measure of its ability to e.pdfThe emissivity of a given surface is the measure of its ability to e.pdf
The emissivity of a given surface is the measure of its ability to e.pdf
info382133
 
Power set={SolutionPower set={.pdf
Power set={SolutionPower set={.pdfPower set={SolutionPower set={.pdf
Power set={SolutionPower set={.pdf
info382133
 
bro Solutionbro .pdf
bro Solutionbro .pdfbro Solutionbro .pdf
bro Solutionbro .pdf
info382133
 
ANSWER Accounting concepts and conventions In dr.pdf
                     ANSWER Accounting concepts and conventions  In dr.pdf                     ANSWER Accounting concepts and conventions  In dr.pdf
ANSWER Accounting concepts and conventions In dr.pdf
info382133
 
As ions are charged species a strong interactions.pdf
                     As ions are charged species a strong interactions.pdf                     As ions are charged species a strong interactions.pdf
As ions are charged species a strong interactions.pdf
info382133
 

More from info382133 (20)

1.) Main characteristics of Haloarchaea are as followsHalophiles .pdf
1.) Main characteristics of Haloarchaea are as followsHalophiles .pdf1.) Main characteristics of Haloarchaea are as followsHalophiles .pdf
1.) Main characteristics of Haloarchaea are as followsHalophiles .pdf
 
1. The three bacteria that may be implicated in the given case are S.pdf
1. The three bacteria that may be implicated in the given case are S.pdf1. The three bacteria that may be implicated in the given case are S.pdf
1. The three bacteria that may be implicated in the given case are S.pdf
 
1. Pros and Cons of IP CCTVNew threats are introduced to the secu.pdf
1. Pros and Cons of IP CCTVNew threats are introduced to the secu.pdf1. Pros and Cons of IP CCTVNew threats are introduced to the secu.pdf
1. Pros and Cons of IP CCTVNew threats are introduced to the secu.pdf
 
1. Activation of Vit. D involves Kidney and Liver and liver is part .pdf
1. Activation of Vit. D involves Kidney and Liver and liver is part .pdf1. Activation of Vit. D involves Kidney and Liver and liver is part .pdf
1. Activation of Vit. D involves Kidney and Liver and liver is part .pdf
 
Rf = (distance the spot traveled)L there are fou.pdf
                     Rf = (distance the spot traveled)L there are fou.pdf                     Rf = (distance the spot traveled)L there are fou.pdf
Rf = (distance the spot traveled)L there are fou.pdf
 
No. Since sodium chloride is an ionic compound, i.pdf
                     No. Since sodium chloride is an ionic compound, i.pdf                     No. Since sodium chloride is an ionic compound, i.pdf
No. Since sodium chloride is an ionic compound, i.pdf
 
Nacl is highly ionic in nature. where as CaO is s.pdf
                     Nacl is highly ionic in nature. where as CaO is s.pdf                     Nacl is highly ionic in nature. where as CaO is s.pdf
Nacl is highly ionic in nature. where as CaO is s.pdf
 
it is reduced as it accepts e- and goes from 0 to.pdf
                     it is reduced as it accepts e- and goes from 0 to.pdf                     it is reduced as it accepts e- and goes from 0 to.pdf
it is reduced as it accepts e- and goes from 0 to.pdf
 
Iodine test is used to see if a compound has star.pdf
                     Iodine test is used to see if a compound has star.pdf                     Iodine test is used to see if a compound has star.pdf
Iodine test is used to see if a compound has star.pdf
 
I have no clue! .pdf
                     I have no clue!                                  .pdf                     I have no clue!                                  .pdf
I have no clue! .pdf
 
C only III is major product .pdf
                     C only III is major product                      .pdf                     C only III is major product                      .pdf
C only III is major product .pdf
 
Borane-THF is flammable and highly reactive with .pdf
                     Borane-THF is flammable and highly reactive with .pdf                     Borane-THF is flammable and highly reactive with .pdf
Borane-THF is flammable and highly reactive with .pdf
 
Ubiquity Internet is available everywhere namely at home, at work v.pdf
Ubiquity Internet is available everywhere namely at home, at work v.pdfUbiquity Internet is available everywhere namely at home, at work v.pdf
Ubiquity Internet is available everywhere namely at home, at work v.pdf
 
Water is the most used resource in our day to day life . When the wa.pdf
Water is the most used resource in our day to day life . When the wa.pdfWater is the most used resource in our day to day life . When the wa.pdf
Water is the most used resource in our day to day life . When the wa.pdf
 
The initiation of the sporulation of the bacteria is a complex cellu.pdf
The initiation of the sporulation of the bacteria is a complex cellu.pdfThe initiation of the sporulation of the bacteria is a complex cellu.pdf
The initiation of the sporulation of the bacteria is a complex cellu.pdf
 
The emissivity of a given surface is the measure of its ability to e.pdf
The emissivity of a given surface is the measure of its ability to e.pdfThe emissivity of a given surface is the measure of its ability to e.pdf
The emissivity of a given surface is the measure of its ability to e.pdf
 
Power set={SolutionPower set={.pdf
Power set={SolutionPower set={.pdfPower set={SolutionPower set={.pdf
Power set={SolutionPower set={.pdf
 
bro Solutionbro .pdf
bro Solutionbro .pdfbro Solutionbro .pdf
bro Solutionbro .pdf
 
ANSWER Accounting concepts and conventions In dr.pdf
                     ANSWER Accounting concepts and conventions  In dr.pdf                     ANSWER Accounting concepts and conventions  In dr.pdf
ANSWER Accounting concepts and conventions In dr.pdf
 
As ions are charged species a strong interactions.pdf
                     As ions are charged species a strong interactions.pdf                     As ions are charged species a strong interactions.pdf
As ions are charged species a strong interactions.pdf
 

Recently uploaded

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
PedroFerreira53928
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
Col Mukteshwar Prasad
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
Celine George
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
PedroFerreira53928
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
Vivekanand Anglo Vedic Academy
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
bennyroshan06
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 

Recently uploaded (20)

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 

Please follow the data 1) For Line 23 In the IF - Condition yo.pdf

  • 1. Please follow the data : 1) For Line 23 : In the IF - Condition you are just checking the cells of the grid at positions 0 and 1. But I suppose you would like to check if both the cells are having the character value 'x'. So to achieve this you need to replace the code with if(grid[0] == grid[1] == 'x') 2) For Line 29 : The error is that the function has been define before the error line and the loop has not been closed so pplace a closing brackets for the loop before the line starting with bool tie() 3) For Line 37 : The above change should also resolve this as the scope of the main function isnt predefined. 4) For Line 69 : Remove the excess bracket at the end of the code. Even after replacing these I suppose your code would not work as the input has not been defined from where and how thw user can get the data to the code. So to avoid this I am placing my code. Please follow the code and comments for descripiton : CODE : #include using namespace std; int checkWin( char[]); // rewuired variables void grid( char[]); int main() { char cell[10] = {'o','1','2','3','4','5','6','7','8','9'}; // placing the cell names int player = 1,i,choice; // initialisations char symbol; do // looping to get the player choices { grid(cell); if(player%2==1) { // checking for the player player=1; } else { player=2; }
  • 2. // player 2 is the computer if(player==2) // if is a player 2 { cout << "Player " << player<> choice; symbol='X'; if (choice == 1 && cell[1] == '1') { cell[1] = symbol; } else if (choice == 2 && cell[2] == '2') { cell[2] = symbol; } else if (choice == 3 && cell[3] == '3') { cell[3] = symbol; } else if (choice == 4 && cell[4] == '4') { cell[4] = symbol; } else if (choice == 5 && cell[5] == '5') { cell[5] = symbol; } else if (choice == 6 && cell[6] == '6') { cell[6] = symbol; } else if (choice == 7 && cell[7] == '7') { cell[7] = symbol; } else if (choice == 8 && cell[8] == '8') { cell[8] = symbol; } else if (choice == 9 && cell[9] == '9') { cell[9] = symbol; } else { cout<<"Invalid move..!!!"<< endl; player--; exit(0);
  • 3. } i=checkWin(cell); player++; } } while(i==-1); grid(cell); if(i==1) { cout<<"Congratulations! Player "<<--player<<" won the Game..!!"; } else { cout<<" OOPS..!!!! The Game has been tie..!!"; } exit(0); return 0; } void grid(char cell[]) // printing the grid everytime the user has placed the symbol { system("cls"); cout << " tTic Tac Toe Game "; cout << "Player 1 (X) - Player 2 (O)" << endl << endl; cout << endl; cout << " | | " << endl; cout << " " << cell[1] << " | " << cell[2] << " | " << cell[3] << endl; cout << "_____|_____|_____" << endl; cout << " | | " << endl; cout << " " << cell[4] << " | " << cell[5] << " | " << cell[6] << endl; cout << "_____|_____|_____" << endl; cout << " | | " << endl; cout << " " << cell[7] << " | " << cell[8] << " | " << cell[9] << endl; cout << " | | " << endl << endl; } int checkWin(char cell[])// checking for the win condition { if (cell[1] == cell[2] && cell[2] == cell[3]) { return 1; }
  • 4. else if (cell[4] == cell[5] && cell[5] == cell[6]) { return 1; } else if (cell[7] == cell[8] && cell[8] == cell[9]) { return 1; } else if (cell[1] == cell[4] && cell[4] == cell[7]) { return 1; } else if (cell[2] == cell[5] && cell[5] == cell[8]) { return 1; } else if (cell[3] == cell[6] && cell[6] == cell[9]) { return 1; } else if (cell[1] == cell[5] && cell[5] == cell[9]) { return 1; } else if (cell[3] == cell[5] && cell[5] == cell[7]) { return 1; } else if (cell[1] != '1' && cell[2] != '2' && cell[3] != '3' && cell[4] != '4' && cell[5] != '5' && cell[6] != '6' && cell[7] != '7' && cell[8] != '8' && cell[9] != '9') { return 0; } else { return -1; } } OUTPUT : 1) For a Tie Game Case : Tic Tac Toe Game Player 1 (X) - Player 2 (O) | |
  • 5. 1 | 2 | 3 _____|_____|_____ | | 4 | 5 | 6 _____|_____|_____ | | 7 | 8 | 9 | | Player 1, Please enter the grid number to place the symbol : 7 Tic Tac Toe Game Player 1 (X) - Player 2 (O) | | 1 | 2 | 3 _____|_____|_____ | | 4 | 5 | 6 _____|_____|_____ | | X | 8 | 9 | | Player 2 Press Enter for the Computer Turn..!! Tic Tac Toe Game Player 1 (X) - Player 2 (O) | | O | 2 | 3 _____|_____|_____ | | 4 | 5 | 6 _____|_____|_____ | |
  • 6. X | 8 | 9 | | Tic Tac Toe Game Player 1 (X) - Player 2 (O) | | O | 2 | 3 _____|_____|_____ | | 4 | 5 | 6 _____|_____|_____ | | X | 8 | 9 | | Player 1, Please enter the grid number to place the symbol : 5 Tic Tac Toe Game Player 1 (X) - Player 2 (O) | | O | 2 | 3 _____|_____|_____ | | 4 | X | 6 _____|_____|_____ | | X | 8 | 9 | | Player 2 Press Enter for the Computer Turn..!! Tic Tac Toe Game Player 1 (X) - Player 2 (O) | | O | 2 | O
  • 7. _____|_____|_____ | | 4 | X | 6 _____|_____|_____ | | X | 8 | 9 | | Tic Tac Toe Game Player 1 (X) - Player 2 (O) | | O | 2 | O _____|_____|_____ | | 4 | X | 6 _____|_____|_____ | | X | 8 | 9 | | Player 1, Please enter the grid number to place the symbol : 2 Tic Tac Toe Game Player 1 (X) - Player 2 (O) | | O | X | O _____|_____|_____ | | 4 | X | 6 _____|_____|_____ | | X | 8 | 9 | | Player 2 Press Enter for the Computer Turn..!!
  • 8. Tic Tac Toe Game Player 1 (X) - Player 2 (O) | | O | X | O _____|_____|_____ | | 4 | X | O _____|_____|_____ | | X | 8 | 9 | | Tic Tac Toe Game Player 1 (X) - Player 2 (O) | | O | X | O _____|_____|_____ | | 4 | X | O _____|_____|_____ | | X | 8 | 9 | | Player 1, Please enter the grid number to place the symbol : 4 Tic Tac Toe Game Player 1 (X) - Player 2 (O) | | O | X | O _____|_____|_____ | | X | X | O _____|_____|_____ | |
  • 9. X | 8 | 9 | | Player 2 Press Enter for the Computer Turn..!! Tic Tac Toe Game Player 1 (X) - Player 2 (O) | | O | X | O _____|_____|_____ | | X | X | O _____|_____|_____ | | X | O | 9 | | Tic Tac Toe Game Player 1 (X) - Player 2 (O) | | O | X | O _____|_____|_____ | | X | X | O _____|_____|_____ | | X | O | 9 | | Player 1, Please enter the grid number to place the symbol : 9 Tic Tac Toe Game Player 1 (X) - Player 2 (O) | | O | X | O
  • 10. _____|_____|_____ | | X | X | O _____|_____|_____ | | X | O | X | | OOPS..!!!! The Game has been tie..!! 2) For Win Case : Tic Tac Toe Game Player 1 (X) - Player 2 (O) | | 1 | 2 | 3 _____|_____|_____ | | 4 | 5 | 6 _____|_____|_____ | | 7 | 8 | 9 | | Player 1, Please enter the grid number to place the symbol : 1 Tic Tac Toe Game Player 1 (X) - Player 2 (O) | | X | 2 | 3 _____|_____|_____ | | 4 | 5 | 6 _____|_____|_____ | | 7 | 8 | 9
  • 11. | | Player 2 Press Enter for the Computer Turn..!! Tic Tac Toe Game Player 1 (X) - Player 2 (O) | | X | 2 | 3 _____|_____|_____ | | 4 | 5 | 6 _____|_____|_____ | | O | 8 | 9 | | Tic Tac Toe Game Player 1 (X) - Player 2 (O) | | X | 2 | 3 _____|_____|_____ | | 4 | 5 | 6 _____|_____|_____ | | O | 8 | 9 | | Player 1, Please enter the grid number to place the symbol : 2 Tic Tac Toe Game Player 1 (X) - Player 2 (O) | | X | X | 3 _____|_____|_____
  • 12. | | 4 | 5 | 6 _____|_____|_____ | | O | 8 | 9 | | Player 2 Press Enter for the Computer Turn..!! Tic Tac Toe Game Player 1 (X) - Player 2 (O) | | X | X | 3 _____|_____|_____ | | 4 | O | 6 _____|_____|_____ | | O | 8 | 9 | | Tic Tac Toe Game Player 1 (X) - Player 2 (O) | | X | X | 3 _____|_____|_____ | | 4 | O | 6 _____|_____|_____ | | O | 8 | 9 | | Player 1, Please enter the grid number to place the symbol : 3 Tic Tac Toe Game
  • 13. Player 1 (X) - Player 2 (O) | | X | X | X _____|_____|_____ | | 4 | O | 6 _____|_____|_____ | | O | 8 | 9 | | Congratulations! Player 1 won the Game..!! Hope this is helpful. Solution Please follow the data : 1) For Line 23 : In the IF - Condition you are just checking the cells of the grid at positions 0 and 1. But I suppose you would like to check if both the cells are having the character value 'x'. So to achieve this you need to replace the code with if(grid[0] == grid[1] == 'x') 2) For Line 29 : The error is that the function has been define before the error line and the loop has not been closed so pplace a closing brackets for the loop before the line starting with bool tie() 3) For Line 37 : The above change should also resolve this as the scope of the main function isnt predefined. 4) For Line 69 : Remove the excess bracket at the end of the code. Even after replacing these I suppose your code would not work as the input has not been defined from where and how thw user can get the data to the code. So to avoid this I am placing my code. Please follow the code and comments for descripiton : CODE : #include
  • 14. using namespace std; int checkWin( char[]); // rewuired variables void grid( char[]); int main() { char cell[10] = {'o','1','2','3','4','5','6','7','8','9'}; // placing the cell names int player = 1,i,choice; // initialisations char symbol; do // looping to get the player choices { grid(cell); if(player%2==1) { // checking for the player player=1; } else { player=2; } // player 2 is the computer if(player==2) // if is a player 2 { cout << "Player " << player<> choice; symbol='X'; if (choice == 1 && cell[1] == '1') { cell[1] = symbol; } else if (choice == 2 && cell[2] == '2') { cell[2] = symbol; } else if (choice == 3 && cell[3] == '3') { cell[3] = symbol; } else if (choice == 4 && cell[4] == '4') { cell[4] = symbol; } else if (choice == 5 && cell[5] == '5') { cell[5] = symbol;
  • 15. } else if (choice == 6 && cell[6] == '6') { cell[6] = symbol; } else if (choice == 7 && cell[7] == '7') { cell[7] = symbol; } else if (choice == 8 && cell[8] == '8') { cell[8] = symbol; } else if (choice == 9 && cell[9] == '9') { cell[9] = symbol; } else { cout<<"Invalid move..!!!"<< endl; player--; exit(0); } i=checkWin(cell); player++; } } while(i==-1); grid(cell); if(i==1) { cout<<"Congratulations! Player "<<--player<<" won the Game..!!"; } else { cout<<" OOPS..!!!! The Game has been tie..!!"; } exit(0); return 0; } void grid(char cell[]) // printing the grid everytime the user has placed the symbol { system("cls"); cout << " tTic Tac Toe Game "; cout << "Player 1 (X) - Player 2 (O)" << endl << endl; cout << endl;
  • 16. cout << " | | " << endl; cout << " " << cell[1] << " | " << cell[2] << " | " << cell[3] << endl; cout << "_____|_____|_____" << endl; cout << " | | " << endl; cout << " " << cell[4] << " | " << cell[5] << " | " << cell[6] << endl; cout << "_____|_____|_____" << endl; cout << " | | " << endl; cout << " " << cell[7] << " | " << cell[8] << " | " << cell[9] << endl; cout << " | | " << endl << endl; } int checkWin(char cell[])// checking for the win condition { if (cell[1] == cell[2] && cell[2] == cell[3]) { return 1; } else if (cell[4] == cell[5] && cell[5] == cell[6]) { return 1; } else if (cell[7] == cell[8] && cell[8] == cell[9]) { return 1; } else if (cell[1] == cell[4] && cell[4] == cell[7]) { return 1; } else if (cell[2] == cell[5] && cell[5] == cell[8]) { return 1; } else if (cell[3] == cell[6] && cell[6] == cell[9]) { return 1; } else if (cell[1] == cell[5] && cell[5] == cell[9]) { return 1; } else if (cell[3] == cell[5] && cell[5] == cell[7]) { return 1;
  • 17. } else if (cell[1] != '1' && cell[2] != '2' && cell[3] != '3' && cell[4] != '4' && cell[5] != '5' && cell[6] != '6' && cell[7] != '7' && cell[8] != '8' && cell[9] != '9') { return 0; } else { return -1; } } OUTPUT : 1) For a Tie Game Case : Tic Tac Toe Game Player 1 (X) - Player 2 (O) | | 1 | 2 | 3 _____|_____|_____ | | 4 | 5 | 6 _____|_____|_____ | | 7 | 8 | 9 | | Player 1, Please enter the grid number to place the symbol : 7 Tic Tac Toe Game Player 1 (X) - Player 2 (O) | | 1 | 2 | 3 _____|_____|_____ | | 4 | 5 | 6 _____|_____|_____
  • 18. | | X | 8 | 9 | | Player 2 Press Enter for the Computer Turn..!! Tic Tac Toe Game Player 1 (X) - Player 2 (O) | | O | 2 | 3 _____|_____|_____ | | 4 | 5 | 6 _____|_____|_____ | | X | 8 | 9 | | Tic Tac Toe Game Player 1 (X) - Player 2 (O) | | O | 2 | 3 _____|_____|_____ | | 4 | 5 | 6 _____|_____|_____ | | X | 8 | 9 | | Player 1, Please enter the grid number to place the symbol : 5 Tic Tac Toe Game Player 1 (X) - Player 2 (O) | |
  • 19. O | 2 | 3 _____|_____|_____ | | 4 | X | 6 _____|_____|_____ | | X | 8 | 9 | | Player 2 Press Enter for the Computer Turn..!! Tic Tac Toe Game Player 1 (X) - Player 2 (O) | | O | 2 | O _____|_____|_____ | | 4 | X | 6 _____|_____|_____ | | X | 8 | 9 | | Tic Tac Toe Game Player 1 (X) - Player 2 (O) | | O | 2 | O _____|_____|_____ | | 4 | X | 6 _____|_____|_____ | | X | 8 | 9 | | Player 1, Please enter the grid number to place the symbol : 2
  • 20. Tic Tac Toe Game Player 1 (X) - Player 2 (O) | | O | X | O _____|_____|_____ | | 4 | X | 6 _____|_____|_____ | | X | 8 | 9 | | Player 2 Press Enter for the Computer Turn..!! Tic Tac Toe Game Player 1 (X) - Player 2 (O) | | O | X | O _____|_____|_____ | | 4 | X | O _____|_____|_____ | | X | 8 | 9 | | Tic Tac Toe Game Player 1 (X) - Player 2 (O) | | O | X | O _____|_____|_____ | | 4 | X | O
  • 21. _____|_____|_____ | | X | 8 | 9 | | Player 1, Please enter the grid number to place the symbol : 4 Tic Tac Toe Game Player 1 (X) - Player 2 (O) | | O | X | O _____|_____|_____ | | X | X | O _____|_____|_____ | | X | 8 | 9 | | Player 2 Press Enter for the Computer Turn..!! Tic Tac Toe Game Player 1 (X) - Player 2 (O) | | O | X | O _____|_____|_____ | | X | X | O _____|_____|_____ | | X | O | 9 | | Tic Tac Toe Game Player 1 (X) - Player 2 (O)
  • 22. | | O | X | O _____|_____|_____ | | X | X | O _____|_____|_____ | | X | O | 9 | | Player 1, Please enter the grid number to place the symbol : 9 Tic Tac Toe Game Player 1 (X) - Player 2 (O) | | O | X | O _____|_____|_____ | | X | X | O _____|_____|_____ | | X | O | X | | OOPS..!!!! The Game has been tie..!! 2) For Win Case : Tic Tac Toe Game Player 1 (X) - Player 2 (O) | | 1 | 2 | 3 _____|_____|_____ | | 4 | 5 | 6 _____|_____|_____
  • 23. | | 7 | 8 | 9 | | Player 1, Please enter the grid number to place the symbol : 1 Tic Tac Toe Game Player 1 (X) - Player 2 (O) | | X | 2 | 3 _____|_____|_____ | | 4 | 5 | 6 _____|_____|_____ | | 7 | 8 | 9 | | Player 2 Press Enter for the Computer Turn..!! Tic Tac Toe Game Player 1 (X) - Player 2 (O) | | X | 2 | 3 _____|_____|_____ | | 4 | 5 | 6 _____|_____|_____ | | O | 8 | 9 | | Tic Tac Toe Game Player 1 (X) - Player 2 (O) | |
  • 24. X | 2 | 3 _____|_____|_____ | | 4 | 5 | 6 _____|_____|_____ | | O | 8 | 9 | | Player 1, Please enter the grid number to place the symbol : 2 Tic Tac Toe Game Player 1 (X) - Player 2 (O) | | X | X | 3 _____|_____|_____ | | 4 | 5 | 6 _____|_____|_____ | | O | 8 | 9 | | Player 2 Press Enter for the Computer Turn..!! Tic Tac Toe Game Player 1 (X) - Player 2 (O) | | X | X | 3 _____|_____|_____ | | 4 | O | 6 _____|_____|_____ | | O | 8 | 9
  • 25. | | Tic Tac Toe Game Player 1 (X) - Player 2 (O) | | X | X | 3 _____|_____|_____ | | 4 | O | 6 _____|_____|_____ | | O | 8 | 9 | | Player 1, Please enter the grid number to place the symbol : 3 Tic Tac Toe Game Player 1 (X) - Player 2 (O) | | X | X | X _____|_____|_____ | | 4 | O | 6 _____|_____|_____ | | O | 8 | 9 | | Congratulations! Player 1 won the Game..!! Hope this is helpful.