私は、配列内の数字を選択して移動するためのCプログラムを構築しています。私の目的は、配列内に同じ数の2つの数字を接続することです。しかし、私はなぜ選択された番号が動かないのか分かりません。助けが必要です、事前に感謝します。数字の選択と移動
ここに私のコードは次のとおりです。例えば
void playgame(char box[ROW][COL])
{
int x, y, choice2,num,direction=0;
char input;
do{
printf("Please select a number (1-7) : ");
scanf("%i",&num);
if(num==0 ||num > 7)
{
printf("Invalid!\n");
}
else
{
printf("\nNumer %i is currently selected!\n", num);
}
}while(num==0 ||num > 7);
printf("\n[1]Move\n[2]Sign out\n");
printf("\nEnter choice: \n");
scanf("%d", &choice2);
switch(choice2)
{
case 1:
{
printf("Press 'e' to go up\n");
/*codes for moving the character up.....*/
}
{
printf("Press 'd' to go right\n");
}
{
printf("Press 's' to go left\n");
}
{
printf("Press 'x' to go down\n");
}
fflush(stdin);
scanf("%c", &input);
break;
case 2: printf("Bye!\n");
}
for(x=0; x<9; x++)
for(y=0; y<9; y++)
{
if(input == 'e')
if(box[x][y]==num)
{
box[--x][y]==num;
}
if(input == 'd')
if(box[x][y]==num)
{
box[x][++y]==num;
}
if(input == 's')
if(box[x][y]== num)
{
box[x][--y]== num;
}
if(input == 'x')
if(box[x][y]==num)
{
box[++x][y]==num;
}
}
}
: numbers
もっと正確に入力してください。 「動けない」とはどういう意味ですか?正確な入力、期待される出力、実際の出力を提供してください。 – kaylum
コードを正しくフォーマットしてください。また、ユーザーが番号を入力するので、質問から「ランダム」という単語を削除する必要があります。そして、あなたは完全なプログラムを提供すべきです...この断片から、 'box 'に何が含まれているかを知る方法はありません。 –