伪随机的猜数游戏

#define _CRT_SECURE_NO_WARNINGS 1
#include
#include
#include
void menu()
{
	printf("*****************************************\n");
	printf("*****************************************\n");
	printf("***********   1.game start   ************\n");
	printf("***********   0.exit         ************\n");
	printf("*****************************************\n");
	printf("*****************************************\n");
	printf("*****************************************\n");
}
void game()
{
	int a = rand() % 100;
	int input=0;
	printf("有个数字在0~99之间\n请输入猜测的数字:>");
	scanf("%d",&input);
	while (input!=a)
	{
		int left = 0;
		int right = 99;
		if (input>a)
		{
			printf("猜大了\n请重新输入:>");
			scanf("%d", &input);
		}
		else
		{
			printf("猜小了\n请重新输入:>");
			scanf("%d", &input);
		}
	}
	printf("恭喜你,猜对了!\n");	
}
void main()
{
	srand((unsigned int)time(NULL));
		int input=0;
	do
	{
		menu();
		scanf("%d", &input);
		switch (input)
		{
		case 1:
			game();
			break;
		case 0:
			break;
		default:
			printf("请重新选择!\n");
			break;
		}
	} while (input);
}

你可能感兴趣的:(c语言练习,c语言,游戏)