waiting.cpp 597 B

12345678910111213141516171819
  1. // waiting.cpp -- using clock() in a time-delay loop
  2. #include <iostream>
  3. #include <ctime> // describes clock() function, clock_t type
  4. int main()
  5. {
  6. using namespace std;
  7. cout << "Enter the delay time, in seconds: ";
  8. float secs;
  9. cin >> secs;
  10. clock_t delay = secs * CLOCKS_PER_SEC; // convert to clock ticks
  11. cout << "starting\a\n";
  12. clock_t start = clock();
  13. while (clock() - start < delay ) // wait until time elapses
  14. ; // note the semicolon
  15. cout << "done \a\n";
  16. // cin.get();
  17. // cin.get();
  18. return 0;
  19. }