如有需要自取 代码如下:
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <math.h>
#include<stdlib.h>
#include<time.h>
#include<windows.h>
void menu( )// 主菜单
{
printf("\t\t\t\t********************\t\t\t\t\n");
printf("\t\t\t\t****** 1.play ******\t\t\t\t\n");
printf("\t\t\t\t****** 0.exit ******\t\t\t\t\n");
printf("\t\t\t\t********************\t\t\t\t\n");
}
void game( )
{
int guess = 0;
int r = rand()%100+1;
while (1)
{
printf("\t\t\t\t猜数字:");
scanf("%d",&guess); // 输入自己猜的数字
if (guess < r) //自己猜的数字与随机数比较
{
printf("\t\t\t\t猜小了\n");
}
else if(guess>r)
{
printf("\t\t\t\t猜大了\n");
}
else
{
printf("\t\t\t\tNice! 猜对了\n");
break;
}
}
}
int main(void)
{
int input = 0;
srand((unsigned int)time(NULL));
do
{
menu();
printf("\t\t\t\t请选择(1-100):");
scanf("%d",&input);
switch (input)
{
case 1:
game();
break;
case 0:
printf("\t\t\t\t退出游戏\n");
break;
default:
printf("\t\t\t\t输入错误\n");
break;
}
} while (input);
return 0;
}