我在这里正确传递参数了吗?
Am I passing parameters on properly here?
我正在为课堂制作一个超级简单的井字游戏。为了确定是否在数组的一部分上放置"X"或"O",我建立了一个名为"turn"的整数来确定当前 2 个玩家中的哪一个在玩。
int main()
{
bool win, tie = false;
int input;
char theBoard[LENGTH] = {SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE};
int turn = 1;
showInstructions();
do
{
showBoard(theBoard);
getMove(turn, input, theBoard);
if (turn == 1)
{
turn++;
}
else if (turn == 2)
{
turn--;
}
}
while(win == false || tie == false);
return 0;
这是我的getMove函数。
void getMove(int input, int turn, char theBoard[LENGTH])
{
cout << "Pick a space from 0 - 8" << endl;
cin >> input;
if (input >= 0 && input <= 8)
{
if (turn == 1)
{
theBoard[input] = X;
}
else if (turn == 2)
{
theBoard[input] = O;
}
}
else
{
cout << "Please make a valid move between 0 - 8" << endl;
cin.ignore();
cin.get();
}
}
您可能需要检查您的getMove
声明。你用turn, input, theBoard
main
称呼它,但它期望input, turn, theBoard
。
相关文章:
- 努力将整数转换为链表。不知道我在这里做错了什么
- 根据编译时参数在 C 中重复代码
- 我可以在这里替换什么,因为我不能在 C# 中使用隐式变量的 lambda 函数?
- 当我从下面的代码中删除关键字 virtual 时,它可以正常工作,否则会出现错误。在这里"virtual"字的意义是什么?
- File.cpp.o:OpenPose 标志 CMakeFiles/.. 的多重定义/main.cpp.o:首先在这里定
- 为什么thread_local变量在这里从未初始化?
- 为什么我必须在这里使用dynamic_cast
- 使用参数在 C# 的C++上运行.exe
- 在这里,当我们比较 if(vc[i]==vc1[i]) 时,它是向量数组. 实际上比较的值是多少,
- 如何使用传递给编译器的相同参数在 cmake 中运行命令?
- 我正在尝试使用 while 循环从字符串中删除字母,直到没有字母。我在这里做错了什么?
- 为什么 C++20 中的 [[可能]] 属性在这里引发警告?
- 我在这里正确传递参数了吗?
- 为什么gmp会在这里与"invalid next size"重新定位一起崩溃?
- 模板参数在 C++ 中存储在哪里?
- 类介绍 (c++) 项目希望我们创建两个构造函数,但它们都不需要任何参数 - 我应该在这里做什么?
- 第二个参数和第三个参数在fwrite()中的作用是什么?为什么我们在这里需要 3rcount?
- 为什么我需要在这里指定模板化函数的模板参数类型
- 模板参数推导:哪个编译器在这里
- 为什么模板参数演绎/替换在这里失败?