1、
#include
using namespace std;
#include
int main()
{
srand((unsigned int)time(NULL));
int a = rand() % 100 + 1;
int b;
while(1)
{
cin >> b;
cout <<"b ="<< b << endl;
if(a>b)
{
cout<<"数字过小"<<endl;
}
else if(a<b)
{
cout<<"数字过大"<<endl;
}
else
{
cout <<"你猜对了"<<endl;
break;
}
}
}
2、
#include
using namespace std;
#include
int main()
{
srand((unsigned int)time(NULL));
int a = rand() % 100 + 1;
int b;
while(1)
{
cin >> b;
cout <<"b ="<< b << endl;
if(a=b)
{
cout <<"你猜对了"<<endl;
break;
}
else if(a<b)
{
cout<<"数字过大"<<endl;
}
else
{
cout<<"数字过小"<<endl;
}
}
}