#include "iostream"
#include <time.h>
using namespace std;
void main()
{
srand( (unsigned)time( NULL ) );
int number = rand() % 100;
int count=0;
bool ok=true;
int small=0;
int large=100;
cout<<"猜数字:请输入一个1-100之间的数字"<<endl;
while(ok)
{
int input=0;
cin>>input;
if(input<small||input>large)
{
cout<<"输入的数字,超出了提示的范围,请重新输入"<<endl;
}
else
{
if(input==number)
{
cout<<"恭喜你,用了"<<count+1<<"次机会,猜对了"<<endl;
ok=false;
break;
}
else
{
if(input<number)
{
count++;
cout<<"您用了"<<count<<"次机会"<<endl;
cout<<"缩小范围:"<<input<<"到"<<large<<"之间,继续猜吧"<<endl;
small=input;
}
if(number<input)
{
count++;
cout<<"您用了"<<count<<"次机会"<<endl;
cout<<"缩小范围:"<<""<<small<<"到"<<input<<"之间,继续猜吧"<<endl;
large=input;
}
}
}
}
}