预设一个正整数并限制猜测次数,
猜大了,提示too big;猜小了提示too small;输入负数直接game over
一次猜对:bingo
两次猜对:lucky you
在限制次数内猜对:good guess
限制次数内未猜到:game over
代码如下
#include<stdio.h>
int main()
{
int number,n;
int inp;
int finished=0;
int cnt=0;
scanf("%d %d",&number,&n);
do {
scanf("%d",&inp);
cnt++;
if(inp<0){
printf("Game Over\n");
finished=1;
}else if(inp>number){
printf("Too big\n");
}else if(inp<number){
printf("Too small\n");
}else{ //cnt==number的情况
if (cnt==1){
printf("Bingo!\n");
}else if(cnt<=3){
printf("Lucky You!\n");
}else{
printf("Good Guess!\n");
}
finished =1;
}
if(cnt==n){
if(!finished){
printf("Game Over\n");
finished =1;
}
}
}while(!finished);
return 0;
}