3.猜数游戏 (1)游戏开始,提示"Ganestart!",并随机产生一个1^90 的数让用户猜,用户基础分为10分,猜错一次扣1分。 (2)如果用户猪错,则提示“Too big! ”还是“Too small! (3)如果猜了10次均未猜中,提示"You Failed! The aumber is r”,r为目标数字。 (4)如果猜对,则提示"Congratulation! Your gessind Lerel is S/A/B/C/D/E" ,其中level由用户剩余分数决定。 S: 10分A:9分B:8分C:7分D:6分E: 1^5分
7条回答 默认 最新
- CSDN专家-赖老师(软件之家) 2021-05-21 17:15关注
#include<stdio.h> #include<stdlib.h> #include<time.h> void main() { int ret = 0; int i = 0; int rnd = 0; int level = 10; srand((unsigned int)time(NULL)); ret = rand()%90; printf("Ganestart!\n"); while(1) { printf("请输入一个数:"); scanf("%d",&rnd); if(rnd>ret){ printf("Too big! \n"); }else if(rnd<ret){ printf("Too small! \n"); }else{ break; } level--; if(level<=0){ printf("You Failed! The aumber is r"); exit(0); } } switch(level){ case 10: printf("Congratulation! Your gessind Lerel is S"); break; case 9: printf("Congratulation! Your gessind Lerel is A"); break; case 8: printf("Congratulation! Your gessind Lerel is B"); break; case 7: printf("Congratulation! Your gessind Lerel is C"); break; case 6: printf("Congratulation! Your gessind Lerel is D"); break; case 5: case 4: case 3: case 2: case 1: case 0: printf("Congratulation! Your gessind Lerel is E"); break; } return 0; }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 MATLAB动图的问题
- ¥15 求差集那个函数有问题,有无佬可以解决
- ¥15 【提问】基于Invest的水源涵养
- ¥20 微信网友居然可以通过vx号找到我绑的手机号
- ¥15 寻一个支付宝扫码远程授权登录的软件助手app
- ¥15 解riccati方程组
- ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
- ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
- ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
- ¥50 树莓派安卓APK系统签名