对猜数字游戏的问题,


#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
int main()
{
    int long long a;     //随机数的储存地址
    int long long b = 0; //输入数的储存地址
    int c = 0;           //次数的储存地址
    int d;               //设置你要猜的最大数
    int e = 0;           //机会的储存地址
    int f = 0;           //判断是否继续游戏
    while (1)
    {
        a = rand() % d + 1; //随即生成一个数(小于你设置的数)
        printf("猜数字小游戏\n");
        printf("输入你要设置的最大上限:");
        scanf("%d", &d); //输入数字
        if (d < 100)     //根据设置数字的大小划分难度
        {
            printf("你有3次机会\n");
            e = 3;
        }
        else if (d < 1000 && d >= 100)
        {
            printf("你有5次机会\n");
            e = 5;
        }
        else if (d >= 1000)
        {
            printf("你有10次机会\n");
            e = 10;
        }
        while (c < e)
        {
            printf("请输如你猜的数:");
            scanf("%d", &b);
            if (a > b)
            {
                printf("你猜小了\n");
            }
            else if (a < b)
            {
                printf("你猜大了\n");
                if (b > d) //如果输入的数大于上限进行提示
                {
                    printf("请输入0~%d\n", d);
                }
            }
            else if (a == b)
            {
                printf("恭喜你猜对了,共用了%d次\n", c+1);
                printf("如要继续游戏请输入任意数,如想退出请输入1:");
                scanf("%d", &f); //是否退出的检测
                c = 0;
                if (f == 1)
                    return 0;
            }
            fflush(stdin); //清除scanf
            c++;
        }
        if (c >= e)
        {
            c = 0;
            printf("抱歉你输了\n");
            printf("如要继续游戏请输入任意数,如想退出请输入1:");
            scanf("%d", &f);
            if (f == 1)
                break;
        }
    }
    return 0;
}

猜数字小游戏
输入你要设置的最大上限:5
你有3次机会
请输如你猜的数:5
你猜小了
请输如你猜的数:5
你猜小了
请输如你猜的数:5
你猜小了
抱歉你输了
如要继续游戏请输入任意数,如想退出请输入1:

在运行第一次的时候设置的数比输入小,但显示你猜的数小了

你生成a的时候并没有初始化d,此时d的值为随机值,可能是一个很大的数,所以生成出的a也会很大
有帮助望采纳