猜测商品价格小游戏

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qjt19950610/article/details/79424992
#include <stdio.h>
#include <stdlib.h>
/*猜测商品价格小游戏*/
int main()
{
    int price;
    int guessprice;
    int count=0;
    srand(time(NULL));//随机函数
    price=rand()%10000;//为了得出一个四位数
    printf("%d",price);
    for(;;count++)
    {
        printf("请输入商品价格:\n");
        scanf("%d",&guessprice);
        if(price>guessprice)
        {
            printf("小了!\n");
        }
        else if(price<guessprice)
        {
            printf("大了!\n");
        }
        else
        {
            printf("恭喜你,猜对了!\n");
            count++;
            break;
        }
    }
    printf("你一共猜测了%d次\n",count);
    if(count<=3)
    {
        printf("哇!你简直就是个天才!\n");
    }
    else
    {
        printf("你也太笨了吧!\n");
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qjt19950610/article/details/79424992
今日推荐