C语言编程如何构建一个简单的猜数字小游戏

源代码如下:

创新互联建站长期为上千家客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为林甸企业提供专业的成都网站建设、成都做网站,林甸网站改版等技术服务。拥有十载丰富建站经验和众多成功案例,为您定制开发。

#include
#include
#include//生成随机函数起点时用到time.h
int main()
{
    int number1 = 0, choice = 0, number2 = 0;
    printf("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n");//界面设置
    printf("$$$$$     欢          迎             来           到     $$$$$\n");
    printf("$$$$$          猜     数      字     游      戏          $$$$$\n");
    printf("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n");
    printf("                         1.进入游戏\n");
    printf("                         2.退出游戏\n");
    scanf("%d", &choice);
        srand((unsigned int)time(NULL));//设置随机数起点
        while (choice == 1)
        {
            printf("请输入所猜的数:\n");
            scanf("%d", &number2);
            number1 = rand() % 100;
            while (1)
            {

                if (number2 == number1)
                {
                    printf("666 恭喜你答对了!");
                    printf("\n1.再玩一次\n2.退出游戏\n");
                    scanf("%d", &number2);
                    if (number2 == 1)
                        break;
                    if (number2 == 2)
                        return 0;
                }

                if (number2 < number1)
                {
                    printf("\n猜小了!\n");
                    scanf("%d", &number2);
                }
                if (number2 > number1)
                {
                    printf("\n猜大了!\n");
                    scanf("%d", &number2);
                }
            }
        }
    while(choice == 2)
    {
        return 0;
    }
    system("pause");
    return 0;
}

运行结果:
C语言编程 如何构建一个简单的猜数字小游戏


网页题目:C语言编程如何构建一个简单的猜数字小游戏
浏览地址:http://myzitong.com/article/gogdhp.html