|错误:' true'未申报(在此功能中首次使用);您的意思是免费吗?
我正在尝试构建猜测游戏。
嗨,我正在尝试在C中构建一个猜测游戏。但是,当我通过true
将循环添加到以下错误时:
error: 'true' undeclared (first use in this function); did you mean 'free'?
我该如何解决?
#include<stdio.h>
#include<stdlib.h>
int main()
{
srand(time(0));
int hidden = rand()%100 +1;
printf("%d\n", hidden);
while (true){
int guess;
scanf("%d", &guess);
if(guess == hidden){
printf("You are right");
break;
}
else if(guess > hidden){
printf("Guess smaller");
}
else{
printf("Guess Larger");
}
}
return 0;
}
I'm trying to build a guessing game.
Hi, I'm trying to build a guessing game in C. But when I pass true
in while loop in throws the following error:
error: 'true' undeclared (first use in this function); did you mean 'free'?
How can I solve this?
#include<stdio.h>
#include<stdlib.h>
int main()
{
srand(time(0));
int hidden = rand()%100 +1;
printf("%d\n", hidden);
while (true){
int guess;
scanf("%d", &guess);
if(guess == hidden){
printf("You are right");
break;
}
else if(guess > hidden){
printf("Guess smaller");
}
else{
printf("Guess Larger");
}
}
return 0;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
true
在stdbool中声明。 H
。您也可以使用
1
而不是true
。true
is declared instdbool.h
.You could also use
1
instead oftrue
.