#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{ int x;
int math;
int count=0;
srand(time(0));
x=rand()%1000;
printf("我从0到999中任意选一个数,请你猜测是哪个数\n");
do{
scanf("%d",&math);
if(math>x){
printf("你的数字大了啊>︿<\n");
}else if(math<x){
printf("你的数字小了啊o(≧口≦)o\n");
}
count ++;
}while(math!=x);
if(count == 1){
printf("666,一次就答对了。啊(?Д?*)?\n");
}else{
printf("恭喜答对了,正确数字是%d,你花了%d次。-O-\n",x,count);
}
return 0;
}
该游戏计算机会从[0,999]中随机抽一个数字,要求玩家猜测计算机随机的数是什么。玩家可以多次猜测,计算机会记录下玩家猜测了多少次。每次猜测,计算机会根据玩家输入的数字,比较随机的数,如果比它大,会提示“你的数字大了”,如果比它小,会提升“你的数字小了”。直到你猜对了这个数字。