C语言实现猜数字游戏

来源:互联网 发布:短信矩阵密码 编辑:程序博客网 时间:2024/06/11 04:07
#define _CRT_SECURE_NO_WARNINGS 1  #include<stdio.h>  #include<stdlib.h>  #include<assert.h>  #include<time.h>void menu(){    printf("*************************\n");    printf("*****1.play   0.exit*****\n");    printf("*************************\n");}void game(){    int key = rand()%100;    int input = 0;    while (1)    {        printf("请输入要猜的数字:>");        scanf("%d",&input);        if (input > key)        {            printf("猜大了\n");        }        else if(input < key)        {            printf("猜小了\n");        }        else        {            printf("恭喜你,猜对了\n");            break;        }    }}int main(){    int choose = 0;    srand((unsigned)time(NULL));    do   {            menu();        printf("请选择:>");        scanf("%d",&choose);        switch (choose)        {            case 0:                exit(1);                break;            case 1:                game();                break;            default:                printf("输入无效,请重新选择>\n");                break;         }   }    while (choose);    system("pause");    return 0;}
原创粉丝点击