#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(int argc, char * argv[])
{
int computer = 0,play = 0,jihui=10;
int now = 1,shengyu,flag = 1;
shengyu = jihui - now;
srand(time(NULL));
computer = rand()%1000;
while(flag){
if(now <= jihui){
printf("请输入一个数字!\n");
scanf("%d", &play);
if(computer > play){
printf("猜小了,第%d次猜,您还有%d次机会,请重新输入\n",now,shengyu);
}
else if(computer < play){
printf("猜大了,第%d次猜,您还有%d次机会,请重新输入\n",now,shengyu);
}
else {
printf("恭喜你,猜对了");
flag=0;
}
now=now+1;
shengyu=jihui-now;
}else{
printf("太笨了,您不适合玩游戏\n");
flag = 0;
}
}
getchar();
return 0;
} |
|