Wait for a period of time: write delay loop

    #include <iostream>
    #include <ctime>
 
    int main()
    {
        using namespace std;
    cout << "Enter the delay time, in seconds: ";
    float secs;
    cin >> secs;
    clock_t delay = secs * CLOCKS_PER_SEC;
    cout << "starting\a\n";
    clock_t start = clock();
    while (clock() - start < delay)
        ;
    cout << "done\a\n";
    return 0;
    }

 

posted @ 2013-12-22 22:07  BornThisWay  阅读(117)  评论(0)    收藏  举报