c语言实现简单的猜数字游戏

来源:互联网 发布:qq飞车黄金雷诺数据 编辑:程序博客网 时间:2024/05/29 09:12
#include<stdio.h>#include<time.h>#include<Windows.h>void game()//猜数字游戏功能函数{int num = 0, input = 0;num = rand() % 100 + 1;//获取1-100的一个随机数while (1)//利用if循环判断{printf("请输入数字\n");scanf_s("%d", &input);if (input == num){printf("恭喜,你猜的数字是对的\n");break;}else if (input < num){printf("猜小了\n");}else{printf("猜大了\n");}}}void menu(){printf("**************************************\n");printf("**********1.game        0.exit**********\n");printf("**************************************\n");}int main(){int choice=0;srand((unsigned int)time(NULL));//防止出现的随机数一样do//利用循环实现可以多次玩{menu();printf("请输入选项\n");scanf_s("%d", &choice);switch (choice){case 1:game();break;case 0:break;default:printf("选择错误\n");break;}} while (choice);return 0;}
请大家多多关注我的博客哦,目前正在学习c语言,会将学习所得一一放在博客上。
原创粉丝点击