这是一段代码:(whyerror1.exe)
#include <stdio.h>
#include <stdlib.h>
int i, n, health=100;
int main(void)
{
for (i=0; i<1; i++)
{
printf("health: %d\n",health);
printf("There is meat on the ground.\n");
printf("Will you eat it?\n");
printf("1: yes 2: no\n");
scanf("%d", n);
if(n==1) {
system("cls");
printf("Ate it. \n");
printf("There is no people, so it is safe to eat. \n");
printf("Health is increased.\n");
system("pause>nul");
system("cls");
}
else if(n==2) {
system("cls");
printf("Didn't ate it. \n");
printf("More hunger, less health. \n");
system("pause>nul");
system("cls");
}
else {
printf("select between 1 and 2. \n");
system("pause>nul");
system("cls");
i=-1;
}
}
}
结果:whyerror1.exe 停止工作。为什么会这样?我已经尝试选择其他号码。我试过任何数字!请帮忙!
scanf("%d", n);
应该是:
scanf("%d", &n);
我是一名优秀的程序员,十分优秀!