#include <iostream> //#include <conio.h> char square[10] = ["0","1","2","3","4","5","6","7","8","9"]; int checkwin(); void board(); int main() { int player = 1,i,choice; char mark; clrscr(); do { board(); player=(player%2)?1:2; cout << "Player " << player << ", enter a number: "; cin >> choice; mark=(player == 1) ? "X" : "O"; if (choice == 1 && square[1] == "1") square[1] = mark; else if (choice == 2 && square[2] == "2") square[2] = mark; else if (choice == 3 && square[3] == "3") square[3] = mark; else if (choice == 4 && square[4] == "4") square[4] = mark; else if (choice == 5 && square[5] == "5") square[5] = mark; else if (choice == 6 && square[6] == "6") square[6] = mark; else if (choice == 7 && square[7] == "7") square[7] = mark; else if (choice == 8 && square[8] == "8") square[8] = mark; else if (choice == 9 && square[9] == "9") square[9] = mark; else { cout<<"Invalid move "; player--; getch(); } i=checkwin(); player++; }while(i==-1); board(); if(i==1) cout<<"==>\aPlayer "<<--player<<" win "; else cout<<"==>\aGame draw"; getch(); return 0; } /********************************************* FUNCTION TO RETURN GAME STATUS 1 FOR GAME IS OVER WITH RESULT -1 FOR GAME IS IN PROGRESS O GAME IS OVER AND NO RESULT **********************************************/ int checkwin() { if (square[1] == square[2] && square[2] == square[3]) return 1; else if (square[4] == square[5] && square[5] == square[6]) return 1; else if (square[7] == square[8] && square[8] == square[9]) return 1; else if (square[1] == square[4] && square[4] == square[7]) return 1; else if (square[2] == square[5] && square[5] == square[8]) return 1; else if (square[3] == square[6] && square[6] == square[9]) return 1; else if (square[1] == square[5] && square[5] == square[9]) return 1; else if (square[3] == square[5] && square[5] == square[7]) return 1; else if (square[1] != "1" && square[2] != "2" && square[3] != "3" && square[4] != "4" && square[5] != "5" && square[6] != "6" && square[7] != "7" && square[8] != "8" && square[9] != "9") return 0; else return -1; } /******************************************************************* FUNCTION TO DRAW BOARD OF TIC TAC TOE WITH PLAYERS MARK ********************************************************************/ void board() { clrscr(); cout << "\n\n\tTic Tac Toe\n\n"; cout << "Player 1 (X) - Player 2 (O)" << endl << endl; cout << endl; cout << " | | " << endl; cout << " " << square[1] << " | " << square[2] << " | " << square[3] << endl; cout << "_____|_____|_____" << endl; cout << " | | " << endl; cout << " " << square[4] << " | " << square[5] << " | " << square[6] << endl; cout << "_____|_____|_____" << endl; cout << " | | " << endl; cout << " " << square[7] << " | " << square[8] << " | " << square[9] << endl; cout << " | | " << endl << endl; } /******************************************************************* END OF PROJECT ********************************************************************/
Standard input is empty
prog.cpp:4:20: error: expected identifier before string constant
char square[10] = ["0","1","2","3","4","5","6","7","8","9"];
^
prog.cpp:4:23: error: expected ‘]’ before ‘,’ token
char square[10] = ["0","1","2","3","4","5","6","7","8","9"];
^
prog.cpp:4:23: error: type ‘__lambda0’ with no linkage used to declare function ‘auto __lambda0::operator()() const’ with linkage [-fpermissive]
prog.cpp: In lambda function:
prog.cpp:4:23: error: expected ‘{’ before ‘,’ token
prog.cpp: At global scope:
prog.cpp:4:23: warning: lambda expressions only available with -std=c++11 or -std=gnu++11 [enabled by default]
prog.cpp:4:23: error: array must be initialized with a brace-enclosed initializer
prog.cpp:4:24: error: expected unqualified-id before string constant
char square[10] = ["0","1","2","3","4","5","6","7","8","9"];
^
prog.cpp: In function ‘int main()’:
prog.cpp:12:9: error: ‘clrscr’ was not declared in this scope
clrscr();
^
prog.cpp:17:3: error: ‘cout’ was not declared in this scope
cout << "Player " << player << ", enter a number: ";
^
prog.cpp:17:3: note: suggested alternative:
In file included from prog.cpp:1:0:
/usr/include/c++/4.8/iostream:61:18: note: ‘std::cout’
extern ostream cout; /// Linked to standard output
^
prog.cpp:18:3: error: ‘cin’ was not declared in this scope
cin >> choice;
^
prog.cpp:18:3: note: suggested alternative:
In file included from prog.cpp:1:0:
/usr/include/c++/4.8/iostream:60:18: note: ‘std::cin’
extern istream cin; /// Linked to standard input
^
prog.cpp:19:7: error: invalid conversion from ‘const char*’ to ‘char’ [-fpermissive]
mark=(player == 1) ? "X" : "O";
^
prog.cpp:20:35: warning: comparison with string literal results in unspecified behaviour [-Waddress]
if (choice == 1 && square[1] == "1")
^
prog.cpp:20:35: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
prog.cpp:22:40: warning: comparison with string literal results in unspecified behaviour [-Waddress]
else if (choice == 2 && square[2] == "2")
^
prog.cpp:22:40: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
prog.cpp:24:40: warning: comparison with string literal results in unspecified behaviour [-Waddress]
else if (choice == 3 && square[3] == "3")
^
prog.cpp:24:40: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
prog.cpp:26:40: warning: comparison with string literal results in unspecified behaviour [-Waddress]
else if (choice == 4 && square[4] == "4")
^
prog.cpp:26:40: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
prog.cpp:28:40: warning: comparison with string literal results in unspecified behaviour [-Waddress]
else if (choice == 5 && square[5] == "5")
^
prog.cpp:28:40: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
prog.cpp:30:40: warning: comparison with string literal results in unspecified behaviour [-Waddress]
else if (choice == 6 && square[6] == "6")
^
prog.cpp:30:40: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
prog.cpp:32:40: warning: comparison with string literal results in unspecified behaviour [-Waddress]
else if (choice == 7 && square[7] == "7")
^
prog.cpp:32:40: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
prog.cpp:34:40: warning: comparison with string literal results in unspecified behaviour [-Waddress]
else if (choice == 8 && square[8] == "8")
^
prog.cpp:34:40: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
prog.cpp:36:40: warning: comparison with string literal results in unspecified behaviour [-Waddress]
else if (choice == 9 && square[9] == "9")
^
prog.cpp:36:40: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
prog.cpp:42:10: error: ‘getch’ was not declared in this scope
getch();
^
prog.cpp:49:3: error: ‘cout’ was not declared in this scope
cout<<"==>\aPlayer "<<--player<<" win ";
^
prog.cpp:49:3: note: suggested alternative:
In file included from prog.cpp:1:0:
/usr/include/c++/4.8/iostream:61:18: note: ‘std::cout’
extern ostream cout; /// Linked to standard output
^
prog.cpp:51:3: error: ‘cout’ was not declared in this scope
cout<<"==>\aGame draw";
^
prog.cpp:51:3: note: suggested alternative:
In file included from prog.cpp:1:0:
/usr/include/c++/4.8/iostream:61:18: note: ‘std::cout’
extern ostream cout; /// Linked to standard output
^
prog.cpp:52:8: error: ‘getch’ was not declared in this scope
getch();
^
prog.cpp: In function ‘int checkwin()’:
prog.cpp:80:24: warning: comparison with string literal results in unspecified behaviour [-Waddress]
else if (square[1] != "1" && square[2] != "2" && square[3] != "3" &&
^
prog.cpp:80:24: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
prog.cpp:80:44: warning: comparison with string literal results in unspecified behaviour [-Waddress]
else if (square[1] != "1" && square[2] != "2" && square[3] != "3" &&
^
prog.cpp:80:44: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
prog.cpp:80:64: warning: comparison with string literal results in unspecified behaviour [-Waddress]
else if (square[1] != "1" && square[2] != "2" && square[3] != "3" &&
^
prog.cpp:80:64: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
prog.cpp:81:24: warning: comparison with string literal results in unspecified behaviour [-Waddress]
square[4] != "4" && square[5] != "5" && square[6] != "6" &&
^
prog.cpp:81:24: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
prog.cpp:81:44: warning: comparison with string literal results in unspecified behaviour [-Waddress]
square[4] != "4" && square[5] != "5" && square[6] != "6" &&
^
prog.cpp:81:44: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
prog.cpp:81:64: warning: comparison with string literal results in unspecified behaviour [-Waddress]
square[4] != "4" && square[5] != "5" && square[6] != "6" &&
^
prog.cpp:81:64: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
prog.cpp:82:26: warning: comparison with string literal results in unspecified behaviour [-Waddress]
square[7] != "7" && square[8] != "8" && square[9] != "9")
^
prog.cpp:82:26: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
prog.cpp:82:46: warning: comparison with string literal results in unspecified behaviour [-Waddress]
square[7] != "7" && square[8] != "8" && square[9] != "9")
^
prog.cpp:82:46: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
prog.cpp:82:66: warning: comparison with string literal results in unspecified behaviour [-Waddress]
square[7] != "7" && square[8] != "8" && square[9] != "9")
^
prog.cpp:82:66: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
prog.cpp: In function ‘void board()’:
prog.cpp:96:9: error: ‘clrscr’ was not declared in this scope
clrscr();
^
prog.cpp:97:2: error: ‘cout’ was not declared in this scope
cout << "\n\n\tTic Tac Toe\n\n";
^
prog.cpp:97:2: note: suggested alternative:
In file included from prog.cpp:1:0:
/usr/include/c++/4.8/iostream:61:18: note: ‘std::cout’
extern ostream cout; /// Linked to standard output
^
prog.cpp:98:45: error: ‘endl’ was not declared in this scope
cout << "Player 1 (X) - Player 2 (O)" << endl << endl;
^
prog.cpp:98:45: note: suggested alternative:
In file included from /usr/include/c++/4.8/iostream:39:0,
from prog.cpp:1:
/usr/include/c++/4.8/ostream:564:5: note: ‘std::endl’
endl(basic_ostream<_CharT, _Traits>& __os)
^
Standard output is empty