我正在制作一个随机移动的机器人,但是我遇到了问题。
http://img199.imageshack.us/img199/2599/randommovement.jpg
为什么这段代码没有运行?这有什么问题吗?
# include <iostream.h>
# include <stdlib.h>
# include <time.h>
# include <windows.h>
# include <conio.h>
void gotoxy(int x, int y){
COORD coord;
coord.X = x;
coord.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
void gerakA(int pointX_par, int pointY_par, int stepX_par, int stepY_par);
void gerakB(int pointX_par, int pointY_par, int stepX_par, int stepY_par);
void gerakC(int pointX_par, int pointY_par, int stepX_par, int stepY_par);
void gerakD(int pointX_par, int pointY_par, int stepX_par, int stepY_par);
void gerakE(int pointX_par, int pointY_par, int stepX_par, int stepY_par);
void gerakF(int pointX_par, int pointY_par, int stepX_par, int stepY_par);
void gerakG(int pointX_par, int pointY_par, int stepX_par, int stepY_par);
void gerakH(int pointX_par, int pointY_par, int stepX_par, int stepY_par);
int main()
{
int stepX, stepY;
int z;
int pointX, pointY;
int n;
int random;
cout <<"Enter your starting point:"<<'\n';
cout <<"x:";
cin >> pointX;
cout <<"y:";
cin >> pointY;
cout << "number of step:";
cin >> n;
cout <<"enter the size of step :"<<'\n';
cout <<"x:";
cin >> stepX;
cout <<"y:";
cin >> stepY;
for (z=1; z<=n+1; z++)
{
srand (time(NULL));
random = rand() % 8 + 1;
switch ( random ) {
case 1:
gerakA(int pointX_par, int pointY_par, int stepX_par, int stepY_par);
case 2:
gerakB(int pointX_par, int pointY_par, int stepX_par, int stepY_par);
case 3:
gerakC(int pointX_par, int pointY_par, int stepX_par, int stepY_par);
case 4:
gerakD(int pointX_par, int pointY_par, int stepX_par, int stepY_par);
case 5:
gerakE(int pointX_par, int pointY_par, int stepX_par, int stepY_par);
case 6:
gerakF(int pointX_par, int pointY_par, int stepX_par, int stepY_par);
case 7:
gerakG(int pointX_par, int pointY_par, int stepX_par, int stepY_par);
case 8:
gerakH(int pointX_par, int pointY_par, int stepX_par, int stepY_par);
}
}
getch();
}
void gerakA(int pointX_par, int pointY_par, int stepX_par, int stepY_par){
gotoxy (pointX_par,pointY_par);
pointX_par = pointX_par + stepX_par;
pointY_par = pointY_par;
cout << "0";
}
void gerakB(int pointX_par, int pointY_par, int stepX_par, int stepY_par){
gotoxy (pointX_par,pointY_par);
pointX_par = pointX_par + stepX_par;
pointY_par = pointY_par - stepY_par;
cout << "0";
}
void gerakC(int pointX_par, int pointY_par, int stepX_par, int stepY_par){
gotoxy (pointX_par,pointY_par);
pointX_par = pointX_par;
pointY_par = pointY_par - stepY_par;
cout << "0";
}
void gerakD(int pointX_par, int pointY_par, int stepX_par, int stepY_par){
gotoxy (pointX_par,pointY_par);
pointX_par = pointX_par - stepX_par;
pointY_par = pointY_par - stepY_par;
cout << "0";
}
void gerakE(int pointX_par, int pointY_par, int stepX_par, int stepY_par){
gotoxy (pointX_par,pointY_par);
pointX_par = pointX_par - stepX_par;
pointY_par = pointY_par;
cout << "0";
}
void gerakF(int pointX_par, int pointY_par, int stepX_par, int stepY_par){
gotoxy (pointX_par,pointY_par);
pointX_par = pointX_par - stepX_par;
pointY_par = pointY_par + stepY_par;
cout << "0";
}
void gerakG(int pointX_par, int pointY_par, int stepX_par, int stepY_par){
gotoxy (pointX_par,pointY_par);
pointX_par = pointX_par;
pointY_par = pointY_par + stepY_par;
cout << "0";
}
void gerakH(int pointX_par, int pointY_par, int stepX_par, int stepY_par){
gotoxy (pointX_par,pointY_par);
pointX_par = pointX_par + stepX_par;
pointY_par = pointY_par + stepY_par;
cout << "0";
}
最佳答案
因此,与expected primary-expression before "int"
错误相关的问题是因为您错误地调用了函数:
gerakA(int pointX_par, int pointY_par, int stepX_par, int stepY_par);
^^^ ^^^^ ^^^ ^^^^ ^^^ ^^^^ ^^^ ^^^^
您不必重新声明类型,也不必使用正确的变量名,对于上面的示例来说,它应该是正确的,或者至少根据我的判断:
gerakA(pointX, pointY, stepX, stepY);