#include<bits/stdc++.h>
using namespace std;
int main(){
cout<<" 欢迎来到猜数游戏"<<endl<<"规则:"<<endl<<"1.输入一个数(为1-100),根据提示判断a-b的区间值"<<endl<<"2.你一共有5次机会,若五次机会用光,则视为失败"<<endl<< "按a键开始,b键退出"<<endl;
char oj;
cin>>oj;
if(oj=='a'){
cout<<"请输入一个数";
srand(time(0)); int n,m=1;
int a = rand ()% 100;
int b = rand ()% 100; while(cout<<endl<<"第"<<m<<"次", cin>>n){
m++;
if(m<=5){
if(n>=a&&n<=b||n>=b&&n<=a){
cout<<"你输入的数:"<<n<<endl<<"a与b的值:"<<a<<" "<<b;
break;
}
else{
if(n>a&&n>b){
cout<<"大了";
}
if(n<a&&n<b)cout<<"小了";
}
}
if(m>5){
cout<<"你的机会用完了!";
break;
}
}
}
else if(oj=='b'){
cout<<" ";
}
}
共 2 条回复
666
可以可以!