#ifdef _WIN32
#include <windows.h>
#endif
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
srand((unsigned)time(NULL));
int random = 1 + rand() % 99;
int user_input;
int attempts = 1;
cout << "random = " << random << endl << endl;
/* delet this line if you dont want spoilers ^^^ */
do
{
cout << "----------| ";
cout << attempts << " |----------" << "\n";
attempts++;
cout << "guess a random number 1 - 100" << endl;
cin >> user_input;
cout << endl;
if (user_input > random || user_input < random)
{
cout << "worng try again" << endl;
}
} while (user_input < random || user_input > random);
cout << "you did it!" << endl;
cout.flush();
sleep(1);
cout << "your prize is";
cout.flush();
sleep(1);
cout << ".";
cout.flush();
sleep(1);
cout << ".";
cout.flush();
sleep(1);
cout << "." << endl;
cout.flush();
sleep(1);
cout << "Nothing!";
return 0;
}
我在学校开发一个随机数猜测器,并且使用在线 C++ 编译器,它运行得很好。但是,当我将其移至 Visual Studio 时,它说“sleep(1)”未定义,我不知道如何修复它。
我尝试将 _win34 更改为 _win32,但这不起作用,而且我找不到 unistd.h 的任何替代品。当我运行代码时,我得到的都是相同的错误