#define _CRT_SECURE_NO_WARNINGS 1 //使scanf strcpy strlen能够使用
# include <stdio.h>
# include <string.h>//能够用strlen函数(测量char函数组的长度)
#include<windows.h>//Sleep(延时)
#include<stdlib.h>//使用系统自带的函数
#include<math.h>
#include<stdlib.h>
#include<time.h>
void mnue()
{
printf("***************************\n");
printf("**** 1.PLAY 0.EXIT ****\n");
printf("***************************\n");
}
void game()
{
int ret = 0;
int n = 0;
int i = 0;
int j = 100;
ret = rand() % 100 + 1;
printf("\n游戏开始,请输入一个数字\n\n");
for (i = 0, j = 100;;)
{
scanf("%d", &n);
if (n<=j &&n> ret&&n>=i)
{
j = n;
printf("\n %d - %d \n\n", i, j);
}
else if (n>=i && n< ret&&n<=j)
{
i = n;
printf("\n %d - %d \n\n", i, j);
}
else if (n > j || n < i)
{
printf("\n输入错误,请重新输入\n");
}
else if(n=ret)
{
printf("\nCongratulation!!! you are right\n");
break;
}
}
}
int main()
{
int k = 1;
srand((unsigned int)time(NULL));
do
{
mnue();
scanf("%d", &k);
switch (k)
{
case 1:
game();
break;
case 0:
printf("\n游戏结束,退出游戏\n");
break;
default:
printf("\n输入错误请重新输入");
break;
}
}
while (k);
return 0;
}
听讲课老师讲了一遍,然后自己写了一遍,这是优化之后的第二遍,基础太差,只可以做成这个样子了,希望各位前辈指点,万谢!