C语言小游戏:猜数字

来源:互联网 发布:思迅会计软件 编辑:程序博客网 时间:2024/05/21 09:32

**给大家介绍一个小小的游戏代码,猜数字游戏。
`#define _CRT_SECURE_NO_WARNINGS 1

#define _CRT_SECURE_NO_WARNINGS 1#include <stdio.h>#include <math.h>#include <windows.h>#include <stdlib.h>#include <time.h>void menu(){    printf("*******************************\n");    printf("**    1.play       0.exit    **\n");    printf("*******************************\n");}void game(){    int num = 0;    int input = 0;    num = rand()%100+1;    while(1)    {        printf("请猜数字:>");        scanf("%d", &input);        if(input == num)        {            printf("恭喜你,猜对了\n");            break;        }        else if(input>num)        {            printf("猜大了\n");        }        else        {            printf("猜小了\n");        }    }}int main(){    int input = 0;    srand((unsigned int)time(NULL));    do    {        menu();        printf("请选择:>");        scanf("%d", &input);        switch(input)        {        case 1:            game();            break;        case 0:            printf("退出游戏\n");            break;        default:            printf("选择错误\n");            break;        }    }    while(input);    return 0;}

`**一次游戏体验
感兴趣的朋友们可以玩玩消遣。

原创粉丝点击