#include <stdio.h>
int main()
{
int answer,n;
int guess;
int cnt = 0;
scanf("%d%d", &answer, &n);
scanf("%d", &guess);
cnt = 1; //对应第一次
if(guess > 0){
do{
if(guess == answer){
break;
}
if(guess > answer){
printf("Too big\n");
}
if(guess < answer){
printf("Too small\n");
}
scanf("%d", &guess);
cnt++;
}while(cnt <= n); //此时,cnt=n+1。假设cnt++后cnt=4,符合条件--->cnt++,cnt=5,退出循环。
if(cnt == 1){
printf("Bingo!");
}
else if(cnt > 1 && cnt <= 3){
printf("Lucky You!");
}
else if(cnt > 3 && cnt <= n){
printf("Good Guess!");
}
}
if(cnt == n+1 || guess < 0){
printf("Game Over");
}
return 0;
} //最后,else-if,若一开始的if成立,则不会判断后面的else-if。
翁凯 | PTA习题 | 练习4-6
最新推荐文章于 2024-03-09 18:55:48 发布