制作了一个猜数字的小程序,我想要用循环和sleep(1000)增加一个倒计时的功能 这个功能是输入一个单位位秒的时间 然后进行倒计时,倒计时结束后游戏自动停止
但是发现按游戏进程和倒计时进程无法同时进行
所以这个该怎么改
下面是我的写的小游戏进程代码
#include <iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
srand((unsigned int)time(NULL));
int n=0;
int num = rand() % 100 + 1; //生成1-100随机数
cout << "please input a number (1-100):";
while (n != num)
{
cin >> n;
if (n > num)
{
cout << "too big" << endl;
}
else if(n<num)
{
cout << "to small" << endl;
}
}
cout<<"the number is "<<num<<endl;
system("pause");
return 0;
}