A pause function

I cannot figure out a pause function for C++. Our books are very generic…can you please help?

To pause for a given amount of time, you will need to interface with your environment. But you didn’t indicate what OS your program was running under.

To pause in Windows, you can call the Sleep function, which will put the current thread to “sleep” for the specified number of milliseconds.

If you want to write your own for systems such as DOS, your pause routine will need to sit in a loop until the specified time has elapsed. Something like this:

#include #include void Pause(int nSeconds){   time_t begin, current;   // Get start time   time(&begin);   // Loop until time has elapsed   do {      // Get current time      time(¤t);   } while (difftime(current, begin) < nSeconds);}

Share the Post:
Share on facebook
Share on twitter
Share on linkedin


The Latest

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS