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;
}
}
}
改好了,望采纳,谢谢,代码:
#include<iostream>
#include<time.h>
using namespace std;
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;
}
}
}
效果: