0

ランダムに動くロボットを作っていますが、問題があります。

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";
}
4

1 に答える 1

1

したがって、expected primary-expression before "int"エラーに関連する問題は、関数を間違って呼び出しているためです。

gerakA(int pointX_par, int pointY_par, int stepX_par, int stepY_par);
       ^^^       ^^^^  ^^^       ^^^^  ^^^      ^^^^  ^^^      ^^^^    

型を言い直す必要はなく、正しい変数名を使用していません。上記の例では、そうである必要があります。または、少なくとも私が知ることができることから:

gerakA(pointX, pointY, stepX, stepY);
于 2013-03-26T17:19:16.867 に答える