直接上代码
#include<bits/stdc++.h>
using namespace std;
int main() {
srand(time(0));
int n = rand() % 100 + 1;
cout << "我想了一个数(在1到100之间),你来猜一下吧\n";
cout << "请输入一个数,我会判断它比我想的那个数大了还是小了\n";
int t;
while (1) {
cin >> t;
if (t == n) {
cout << "恭喜你,猜对了!\n";
return 0;
} else if (t < n) {
cout << "小了\n";
} else if (t > n) {
cout << "大了\n";
}
}
return 0;
}
第22次发博客