所以我试图制作一个tic tac toe游戏,但我一直在犯错:
严重级代码描述项目文件行抑制状态 错误LNK2019未解析的外部符号" void __cdecl check(char * const,bool)" (?检查@@ YAXQAD_N @ Z)在函数_main tictac中引用 严重性代码描述项目文件行抑制状态 错误LNK2019未解析的外部符号" void __cdecl WriteTable(char * const)" (?WriteTable @@ YAXQAD @ Z)在函数_main tictac中引用 严重性代码描述项目文件行抑制状态 错误LNK1120 2未解析的外部tictac 我希望你们中的任何人都可以帮助我。 代码:
#include <iostream>
using namespace std;
void check(char t[], bool end);
void WriteTable(char t[]);
void playerX(char t[]);
void playerO(char t[]);
int main() {
bool turn = true;
char t[9] = "";
bool end = false;
do {
WriteTable(t);
if (turn == true) {
playerX(t);
turn = false;
}
else {
playerO(t);
turn = true;
}
check(t, end);
} while (end == false);
system("pause");
return 0;
}
void izpis(char t[]) {
for (int i = 0; i < 9; i++) {
cout << t[i] << " ";
if ((i + 1) % 3 == 0) {
cout << endl;
}
}
}
void playerX(char t[]) {
int a;
cout << "playerX: ";
do {
cin >> a;
if (t[a - 1] == 0) {
t[a - 1] = 'X';
}
} while (t[a - 1] != 'X');
}
void playerO(char t[]) {
int a;
cout << "playerO: ";
do {
cin >> a;
if (t[a - 1] == 0) {
t[a - 1] = 'O';
}
} while (t[a - 1] != 'O');
}
void check(int t[], bool end) {
bool equal = false;
if (t[0] == 'X' || t[1] == 'X' || t[2] == 'X') {
cout << "X won" << endl;
end = true;
}
else if (t[3] == 'X' || t[4] == 'X' || t[5] == 'X') {
cout << "X won" << endl;
end = true;
}
else if (t[6] == 'X' || t[7] == 'X' || t[8] == 'X') {
cout << "X won" << endl;
end = true;
}
else if (t[0] == 'X' || t[3] == 'X' || t[6] == 'X') {
cout << "X won" << endl;
end = true;
}
else if (t[1] == 'X' || t[4] == 'X' || t[7] == 'X') {
cout << "X won" << endl;
end = true;
}
else if (t[2] == 'X' || t[5] == 'X' || t[8] == 'X') {
cout << "X won" << endl;
end = true;
}
else if (t[0] == 'X' || t[3] == 'X' || t[8] == 'X') {
cout << "X won" << endl;
end = true;
}
else if (t[6] == 'X' || t[4] == 'X' || t[2] == 'X') {
cout << "X won" << endl;
end = true;
}
if (t[0] == 'O' || t[1] == 'O' || t[2] == 'O') {
cout << "O won" << endl;
end = true;
}
else if (t[3] == 'O' || t[4] == 'O' || t[5] == 'O') {
cout << "O won" << endl;
end = true;
}
else if (t[6] == 'O' || t[7] == 'O' || t[8] == 'O') {
cout << "O won" << endl;
end = true;
}
else if (t[0] == 'O' || t[3] == 'O' || t[6] == 'O') {
cout << "O won" << endl;
end = true;
}
else if (t[1] == 'O' || t[4] == 'O' || t[7] == 'O') {
cout << "O won" << endl;
end = true;
}
else if (t[2] == 'O' || t[5] == 'O' || t[8] == 'O') {
cout << "O won" << endl;
end = true;
}
else if (t[0] == 'O' || t[3] == 'O' || t[8] == 'O') {
cout << "O won" << endl;
end = true;
}
else if (t[6] == 'O' || t[4] == 'O' || t[2] == 'O') {
cout << "O won" << endl;
end = true;
}
for (int i = 0; i < 9; i++) {
if (t[i] != 'X' && t[i] != 'O') {
break;
}
}
if (equal == false) {
cout << "draw";
end = true;
}
}
答案 0 :(得分:1)
这里有一些问题:
void WriteTable(char t[]);
此函数已声明但从未定义过。你打算如何使用它?
void check(char t[], bool end);
和
void check(int t[], bool end) {
这些签名是否与您匹配?现在问题应该是相当明显的。