在c++中开始一个nQueens游戏.哪里是错误位于我的代码
Beginning of an nQueens game in c++. Where is the error located in my code?
在尝试编译以下代码时,我一直得到错误。错误是
expected ',' or ';' before '{' token.
显示bool check_row(x)
后面的括号有错误如果我把它注释掉,同样的情况也发生在bool check_col(x)
上。如果我没有正确地定义函数,我就会回头看我的书,但它们在逻辑上似乎是正确的。这是一个在4x4棋盘上的nQueens游戏的开始。数字1代表女王。这两个布尔函数用于检查行和列是否空闲。startGame()
将所有盒子赋值为0,showBoard()
显示电路板的结果。
#include <cstdlib>
#include <iostream>
using namespace std;
int x=0, y=0;
int square[4][4];
void startGame()
{
for(x=0;x<4;x++)
{
for(y=0;y<4;y++)
{
square[x][y]=0;
}
}
}
void showBoard()
{
for(int x=0;x<4;x++)
{
if(x!=0)
{
cout<<endl;
}
for(int y=0;y<4;y++)
{
cout<<square[x][y];
}
}
cout<<endl;
}
bool check_row(x)
{
for(y=0;y<4;y++)
{
if(square[x][y]==1)
{
return false;
}
else if(square[x][y]==0)
{
if(y==3)
{
return true;
}
continue;
}
}
}
bool check_col(y)
{
for(int x=0;x<4;x++)
{
if(square[x][y]==1)
{
return false;
}
else if(square[x][y]==0)
{
if(x==3)
{
return true;
}
continue;
}
}
}
int main(){
startGame();
showBoard();
return 0;
}
bool check_col(y)
不是一个有效的原型。您需要为y
(例如bool check_col(int y)
)提供一个类型。这同样适用于bool check_row(x)
您必须指定您在函数中传递的datatype
作为parameter
.考虑到x
和y
是int
类型并且是local
,您的function prototype
应该是
bool check_row(int x)
bool check_col(int y)
如果x
和y
是global
,那么不需要传递它们…
bool check_row()
bool check_col()
将工作,因为global variables
的visibility
将在整个程序中,除非阴影
相关文章:
- 请找出我的代码中的错误,它在提交得到错误答案的同时仍然适用于我的所有测试用例
- Visual C++ wxWidgets应用程序仅适用于我的PC
- 是视觉C++优化器错误还是我的代码中有错误?
- C OPENCV中的错误是我的第一个代码(中值过滤器)
- 这是 Clang 的错误还是我的错误?
- 尝试创建波形着色器,我似乎无法计算法线以将镜面照明应用于我的波形
- 在这种情况下,(N)RVO是否适用于我的功能
- 错误:我的程序中杂散的"\342",但我找不到坏字符
- 当我从 Windows 请求"Miriam"字体时,我得到的是"Arial"字体。这怎么可能,因为字体文件"mriam.ttf"存在于我的系统中?
- 为什么我的函数重载不优先于我的模板化重载
- 如果 else 语句中的 C++ 错误,我的语法有什么问题
- 这是编译器错误还是我的代码?
- 试图理解得墨忒耳定律,因为它适用于我的代码
- 错误 LNK2019 - 我的常用C++代码不起作用
- 如何使阈值窗口仅适用于我的一半图像
- 不断收到处理错误.导致我的程序中断
- QT C++ - 信号和插槽:"No such slot QLabel..."甚至插槽功能也存在于我的类中
- 有一个错误与我的c++类项目
- 为什么我得到所有这些错误在我的c++代码
- 在c++中开始一个nQueens游戏.哪里是错误位于我的代码