#include<iostream>
#include<ctime>//或者time.h,使用随机数种子时用到
using namespace std;
int main()
{
//随机种子,保证程序每次执行时随机数都不一样
srand((unsigned int)time(NULL));
int ch = rand()%100+1;//1到100的随机数
//cout << ch << endl;
int num=0;
cout << "请输入你猜的数" << endl;
cin >> num;
while (num != ch)
{
if (num > ch)
{
cout << "您输入的数字过大,请重新输入" << endl;
cin >> num;
}
else
{
cout << "您输入的数字过小,请重新输入" << endl;
cin >> num;
}
}
cout << "恭喜:" <<ch<< endl;
system("pause");
return 0;
}
网友评论