#include <stdio.h>
#include <stdlib.h>
int main(int argc, const char * argv[]) {
//int i = 0;
//while (i < 100) {
//int r = arc4random_uniform(41)+10;//产生m,n之间的随机数-->arc4random_uniform(n-m+1)+m
//printf("%d\t",r);
//i++;
//}
int randomNum = 0,inputNum = 0;
int m = 1,n = 1000;
int totalCount = 10;
int nowCount = 1;
int flag = 1;
int oldNum = 0;
randomNum = arc4random_uniform(n-m+1)+m;
while (flag) {
if (nowCount <= totalCount) {
printf("请输入[%d,%d]之间的数字\n",m,n);
scanf("%d",&inputNum);
if (inputNum > randomNum) {
printf("你这是第%d次竞猜,\n还有%d次机会竞猜,\n上次竞猜:%d,\n本次竞猜:%d,\n竞猜结果:大了!\n",nowCount,totalCount-nowCount,oldNum,inputNum);
}else if (inputNum < randomNum){
printf("你这是第%d次竞猜,\n还有%d次机会竞猜,\n上次竞猜:%d,\n本次竞猜:%d,\n竞猜结果:小了!\n",nowCount,totalCount-nowCount,oldNum,inputNum);
}else{
printf("你这是第%d次竞猜,\n还有%d次机会竞猜,\n上次竞猜:%d,\n本次竞猜:%d,\n竞猜结果:中了!\n",nowCount,totalCount-nowCount,oldNum,inputNum);
flag = 0;
}
oldNum = inputNum;
nowCount++;
}else{
printf("你的智商不适合玩这个游戏!\n");
flag = 0;
}
}
return 0;
}
|
|