c语言编程练习题:7-24 猜数字游戏
作者:yunjinqi   类别:    日期:2023-05-29 13:24:35    阅读:461 次   消耗积分:0 分    

image.png

#include <stdio.h>
int main(){
    int target_num,total_trial,count=0;
    int my_guess;
    if (scanf("%d %d",&target_num,&total_trial)!=0){
        //printf("game begins,intput a int number \n");
        while (scanf("%d",&my_guess)!=0){
            count = count+1;
            //printf("%d %d %d %d",target_num,total_trial,my_guess,count);
            if (my_guess==target_num && count==1){printf("Bingo!");break;}
            if (my_guess==target_num && count<=3){printf("Lucky You!");break;}
            if (my_guess==target_num && count>3 && count<=total_trial){printf("Good Guess!");break;}
            if (my_guess!=target_num && (count> total_trial || my_guess<0)){printf("Game Over");break;}
            if (my_guess>target_num){printf("Too big\n");}
            if (my_guess<target_num){printf("Too small\n");}
        }
    }else{
        printf("输入的数据存在错误");
    }
    return 0;

}


版权所有,转载本站文章请注明出处:云子量化, http://www.woniunote.com/article/149
上一篇:c语言编程练习题:7-23 分段计算居民水费
下一篇:c语言编程练习题:7-25 求奇数和