Advertisement
Vita94

C++ time

Feb 26th, 2014
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. #include <iostream>
  2. #include <time.h>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     unsigned int st = (unsigned)time(NULL); //start time
  8.     unsigned int ct = (unsigned)time(NULL); //current time
  9.     unsigned int lt = (unsigned)time(NULL); //last time
  10.     int a = 0;
  11.     cout << "Program will close in 10 seconds" << endl;
  12.     cout << st << endl << ct << endl << lt << endl;
  13.     while(ct - st < 10)
  14.     {
  15.  
  16.         ct = (unsigned)time(NULL); //update current time
  17.         if(lt != ct)
  18.         {
  19.             a++;
  20.             cout << a << " seconds have passed!" << endl;
  21.             lt = ct;
  22.         }
  23.     }
  24.     cout << "Hello world!" << endl;
  25.     return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement