温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

C语言实现猜数字游戏源码

发布时间:2020-05-22 11:24:32 来源:亿速云 阅读:257 作者:Leah 栏目:编程语言

今天小编就为大家带来一篇使用C语言实现猜数字游戏的文章。小编觉得挺实用的,为此分享给大家做个参考。一起跟随小编过来看看吧。

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
void menu()
{
    printf("***************************\n");
    printf("*******   1.play    *******\n");
    printf("*******   0.exit    *******\n");
    printf("***************************\n");
}
void game()
{
    int number = rand() % 100 + 1;
    int input = 0;
    while (1)
    {
        printf("请输入猜的数字\n");
        scanf("%d", &input);
        if (input > number)
        {
            printf("提示!猜大了\n");
        }
        else if (input < number)
        {
            printf("提示!猜小了\n");
        }
        else
        {
            printf("恭喜你,猜对了");
            break;
        }
    }
}
int main()
{
    system("color 7F");//78
    int input = 0;
    srand((unsigned)time(NULL));
    do
    {

        menu();
        printf("请选择->");
        scanf("%d", &input);
        switch(input)
        {
        case 1:game();
        case 0:break;
        dafult:printf("选择错误,请重新选择\n");
        }
    } while (input);
    return 0;
}

以上就是C语言实现猜数字游戏的源码,代码详细清楚,如果在日常工作遇到这个问题,希望你能通过这篇文章解决问题。如果想了解更多相关内容,欢迎关注亿速云行业资讯频道!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI