# include <iostream>
# include <string>
# include <cstdlib>
# include <ctime>
using namespace std;
int main(){
// 1. 系统生成0-100之间的随机数;
int rand_num = 0;
const int MIN_NUM = 1;
const int MAX_NUM = 100;
srand((int)time(0));
rand_num = rand()%(MAX_NUM - MIN_NUM) + MIN_NUM;
// cout << rand_num;
//2. 玩家猜数字;
int gust_num = 0;
cout << "请输入你猜的数据(0--100之间),按回车结束:" <<endl;
cin >> gust_num;
//3.猜对结束游戏,猜错继续猜;
while(gust_num != rand_num){
if (gust_num > rand_num){
cout << "很遗憾,猜错了,数字过大,请重猜:" <<endl;
cin >> gust_num;
}
else if (gust_num < rand_num){
cout << "很遗憾,猜错了,数字过小,请重猜:" <<endl;
cin >> gust_num;
}
}
cout << "猜对了,游戏结束!" <<endl;
system("pause");
return 0;
}
11-05
5547
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-17
973
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
07-19
2665
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
02-02
2325
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-12
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交