标签:随机数、循环
#include<iostream>
#include<ctime>
using namespace std;
int main()
{
int a,b,i=1;
srand(time(0));
b=rand()%100+1;
cout<<"请输入一个0~100的数"<<endl;
do
{
cout<<"第"<<i<<"次输入:"<<endl;
cin>>a;
if (a>b)
{
cout<<"太大"<<endl;
}
else if (a<b)
{
cout<<"太小"<<endl;
}
else
{
cout<<"恭喜你猜对了,这个数是"<<a<<endl;
break;
}
i++;
}while(a!=b);
system("pause");
return 0;
}