直接上代码吧
用的是vs2019
#include <iostream>
using namespace std;
int main() {
// 系统生成随机数 // rand()%100 生成 0~99
srand(time(NULL)); // 随机数种子,不加这行下一行就是伪随机数
int random_num = rand() % 100 + 1; // 1-100;
//cout << random_num << endl;
while (true)
{
int guess;
cout << "输出你猜的数:";
cin >> guess;
if (random_num == guess)
{
cout << "恭喜你!猜对了" << endl;
break;
}
else if (random_num > guess)
{
cout << "猜小了!" << endl;
}
else
{
cout << "猜大了!" << endl;
}
}
return 0;
}
标签:rand,guess,cout,int,C++,随机数,100
From: https://www.cnblogs.com/code3/p/17300027.html