数字炸弹
2026-09-08 17:03:50
发布于:浙江
数字炸弹(试试写中文(输入中))
#include<iostream>
#include<ctime>
#include<cstdlib>
#include<cmath>
using namespace std;
int main(){
cout<<"数字炸弹,请输入1~几"<<"\n";
int n;
cin>>n;
srand(time(0));
cout<<"游戏开始,输入0退出" ;
while(1){
int l= 1;
int r= n;
int k= rand()%n+1;
while(l<=r){
cout<<"猜一个数字"<<"\n";
int c;
cin>>c;
if(c==k){
cout<<"猜对了!,下一轮"<<"\n";
break;
}else if(c<k){
l= c+1;
cout<<"小了,区间:"<<l<<"到"<<r<<"\n";
}else if(c==0){
cout<<"已退出";
return 0;
}else if(c<l||c>r){
cout<<"请输入区间内的数!"<<"\n";
}else{
r =c-1;
cout<<"大了,区间:"<<l<<"到"<<r<<"\n";
}
}
}
return 0;
}
这里空空如也




















有帮助,赞一个