Reputation: 3
I have a program like this:
using namespace std;
int main()
{
srand(time());
int izlases_sk, a, b, c, d, e;
cout << "Enter 5 numbers" << endl;
cin >> a;
cin >> b;
cin >> c;
cin >> d;
cin >> e;
cout << endl;
for (int x = 0; x < 20; x++)
{
izlases_sk = rand() % 77;
cout << izlases_sk << "\t";
if( izlases_sk == a || izlases_sk == b || izlases_sk == c || izlases_sk == d || izlases_sk == e)
cout << " You predicted this number!\t";
else
cout << "No\t";
{
if (a > 77 || b > 77 || c > 77 || d > 77 || e > 77)
goto end;
}
if ((x + 1) % 5 == 0)
cout<<endl;
}
end:
getch ();
}
I want that my randomly generated numbers get outputted one by one with 1 second delay in between. How can I do it?
Example: c++ generate 76
, then after one second he generates next number.
Upvotes: 0
Views: 254
Reputation: 15524
If you're using a C++11 compliant compiler then simply insert the following line wherever you want the program to sleep for a second (you need headers <thread>
and <chrono>
):
std::this_thread::sleep_for(std::chrono::seconds(1));
Also this code is portable.
Upvotes: 1