- #include
- using namespace std;
- #include
- int main()
- {
- //添加随机种子,利用系统时间生成随机数
- srand((unsigned int)time(NULL));
- //生成0到99的随机数
- int num = rand() % 100 + 1;
- cout << num << endl;
- int k = 0;
- int count = 0;
- while (1) {
- cin >> k;
- if (k > num) {
- cout << "猜大了" << endl;
- }
- else if (k < num) {
- cout << "猜小了" << endl;
- }
- else {
- cout << "猜对了" << endl;
- break;
- }
- count++;
- if (count == 4) {
- cout << "你真是大聪明" << endl;
- break;
- }
- }
- system("pause");
- return 0;
- }
- #include
- #include
- int main() {
- srand((unsigned int)time(NULL));
- int num = rand() % 100 + 1;
- int k = 0;
- int count = 0;
- while (1) {
- scanf("%d", &k);
- if (k > num) {
- printf("猜大了\n");
- }
- else if (k < num) {
- printf("猜小了\n");
- }
- else {
- printf("猜对了\n");
- break;
- }
- count++;
- if (count == 4) {
- printf("你真是个大聪明\n");
- break;
- }
- }
- return 0;
- }