Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"wait" or "delay" function

Status
Not open for further replies.

ixnay5

MIS
Jan 10, 2002
68
US
Hi all. I have a school project that requires me to build an airport simulator using queues. (If you've ever used Nyhoff's Data Structures text, you may be familiar with this). I don't want it to run real time because it'll blow by the DOS window in a flash and take away all the user's fun. So in each pass thru the simulated control clock loop, I'd like to insert a function call that causes the program to delay for a fixed amount of time, say 1 second.

Can anyone point me to a library function or code snippet that does this sort of thing?
 
I don't remember exactly how to use this function correctly. but while nobady gives you a better advice, I say that you should look for the "Sleep()" fuction.


Holpe it helps


Andre
 
I know that at old trick you can use is to have a for loop that does absolutely nothing. I think on my machine, I just run a variable from 1 to 1000000 or so for a few of the needed delays in my programs. The drawback is that the length of the delay is machine dependant.

I've wondered about a better way, too. I suspect there is some method to get ctime to give you the current time in a workable form. If you could, you might be able to have a loop which waits until that value plus one second.

Is anyone more familiar with the ctime class?

If these methods aren't to your liking, you may also utilize cin.ignore() for keyboard controlled delay.
 
Thanks all!

The windows.h include has the solution:

Sleep(int); //int value in milliseconds

--------

#include <iostream>
#include <windows.h>

using namespace std;

void main()

{

for (int i = 1; i <= 20; i++)

{
Sleep(1000);
cout<<i<<endl;

}

}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top