#include<bits/stdc++.h>
using namespace std;
int main()
{
int count = 0;
int number = 0;
srand((unsigned int)time(NULL));//添加随机数种子 ,当前系统时间生成随机数,防止每次随机数都一样
int answer= rand() % 100 + 1;//生成一个1到100的随机数
cout << "先输入一个数 :" << endl;
while (count < 5)
{
cin >> number;
count++;
if (number < answer)
{
cout << "输入的数小了" << endl;
}
else if (number > answer)
{
cout << "输入的数大了" << endl;
}
else
{
cout << "猜对了!" << endl;
break;
}
}
if (count == 5)
{
cout << "猜错5次,游戏失败" << endl;
}
return 0;
}
09-11
915
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交