|错误:' true'未申报(在此功能中首次使用);您的意思是免费吗?

发布于 2025-01-25 03:33:25 字数 940 浏览 2 评论 0原文

我正在尝试构建猜测游戏。

嗨,我正在尝试在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'?

Screenshot

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

叫思念不要吵 2025-02-01 03:33:25

true stdbool中声明。 H

您也可以使用1而不是true

true is declared in stdbool.h.

You could also use 1 instead of true.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文