栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

【跟着鹏哥学习C语言的小日常】猜数字游戏

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

【跟着鹏哥学习C语言的小日常】猜数字游戏

【跟着鹏哥学习C语言的小日常】猜数字游戏
#define  _CRT_SECURE_NO_WARNINGS 1
#include 
#include 
#include 

void menu()
{
	printf("****************************n");
	printf("*******   1. play    *******n");
	printf("*******   0. exit    *******n");
	printf("****************************n");

}

void game()
{
	//猜数字游戏的实现
	//1.先生成随机数
	//rand函数返回了一个0-32767之间的数字
	//时间-时间戳
	srand((unsigned int)time(NULL));
	int ret = rand()%100+1; //%100的余数是0-99,然后+1,范围就是1-100
	
		//2.猜数字
	int guess = 0;
		while (1)
		{
		printf("请猜数字:>");
		scanf("%d", &guess);
		if (guess < ret)
		{
			printf("猜小了n");
		}
		else if (guess > ret)
		{
			printf("猜大了n");			
		}
		else
		{
			printf("恭喜你,猜对了n");
			break;
		}
		}
}


int main()
{
	int input=0;
	srand((unsigned int)time(NULL));
	do
	{
		menu();//打印菜单
		printf("请选择:>");
		scanf("%d", &input);
		switch (input)
		{
		case 1:
			printf("猜数字n");
			game();
			break;
		case 0:
			break;
		default:
			printf("选择错误,重新选择n");
			break;
		}

	} while (input);
	return 0;
}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/864635.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号