#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void print_menu()
{
printf("**********************\n");
printf("******* 1.start ******\n");
printf("******* 0. exit ******\n");
printf("**********************\n");
}
int main()
{
printf("欢迎使用猜数字游戏\n");
int input = 1;
while (input)
{
print_menu();
printf("请选择>");
scanf("%d", &input);
switch (input)
{
case 1:
{
int n = 0;
int ch = 0;
srand((unsigned int)time(NULL));
n = rand() % 101;
while (1)
{
printf("请猜一个(0-100)直接的数\n");
scanf("%d", &ch);
if (ch > n)
{
printf("你猜大了\n");
}
else if (ch <n)
{
printf("你猜小了\n");
}
else
{
printf("恭喜你,猜对了\n");
break;
}
}
break;
}
default:
printf("游戏退出\n");
break;
}
}
system("pause");
return 0;
}
时间: 2024-12-26 14:06:29