下面的代码假设是从用户那里获得W,A,S或D的键盘输入。当按下每个键时,需要在屏幕上显示不同的消息。我想使用if语句来完成此任务。目前,错误的反应出现了错误的反应。
我得到的当前结果是:
我想要的结果如下:
谢谢
#include <stdio.h>
int main()
{
char keyInput[2];
//Instructions for user to follow
printf("Controls: \n");
printf("W = UP: \n");
printf("A = LEFT \n");
printf("S = DOWN \n");
printf("D = RIGHT \n");
printf("\nWhich direction do you want to go?");
scanf("%s", keyInput);
//choices
if (*keyInput == 'W')
{
printf("Character going UP\n");
}
else if (*keyInput == 'A')
{
printf("Character going LEFT\n");
}
else if (*keyInput == 'S')
{
printf("Character going DOWN\n");
}
else if (*keyInput == 'D');
{
printf("Character going RIGHT\n");
}
return 0;
}
答案 0 :(得分:0)
这一行:
否则if(* keyInput =='D');
不应以分号结尾