完成猜数字游戏。

完成猜数字游戏。 

#include<stdio.h>
#include<time.h>
#include<stdlib.h>
int menu()
{
	int choose = 0;
	printf("************************************\n");
	printf("********  Please choose:   *********\n");
	printf("********  1.Game   0.Exit  *********\n");
	printf("************************************\n");
	while(1)
	{
		scanf("%d",&choose);
		if(1 == choose)
		{
			return 1;
		}
		else if(0 == choose)
		{
			return -1;
		}
		else
		{
			printf("Please choose again!\n");
		}
	}
}

void game()
{
	int num = 0;
	int ret = 0;
	srand((unsigned) time (NULL));
	ret = rand()%100;
	do
	{
		printf("Please input the number you guess:\n");
		scanf("%d",&num);
		if(num > ret)
		{
			printf("It is big.\n");
		}
		else if(num < ret)
		{
			printf("It is small.\n");
		}
		else
		{
			printf("Congratulations, you guessed it!\n");
			break;
		}

	}while(1);
}
int main()
{
	int r = 0;
	while(1)
	{
		r = menu();
		if(1 == r)
		{
			game();
		}
		else
		{
			break;
		}
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/USA_AM_1966/article/details/83745046
今日推荐