gpt4 book ai didi

c - 'For' 中的 'If' 使游戏崩溃 - C 语言

转载 作者:太空宇宙 更新时间:2023-11-04 06:31:21 25 4
gpt4 key购买 nike

这是一段代码:(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);

关于c - 'For' 中的 'If' 使游戏崩溃 - C 语言,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20149286/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com