-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtimer.cpp
More file actions
60 lines (43 loc) · 1.54 KB
/
timer.cpp
File metadata and controls
60 lines (43 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <iostream> //std::cout
#ifdef _WIN32 // winshit :(
#include <Windows.h>
#else // thats better :)
#include <unistd.h>
#endif
// prints time and waits 0.25 seconds
void printTimeCR( // please excuse my Danish abbreviations xD
unsigned int dag,
unsigned char t,
unsigned char min,
unsigned char sek,
unsigned char kvSek
){
char spin; // spinny-thing character
switch (kvSek) { // set spinny thing character
//NOTE: characters are contained in single quotes (not double quotes)
case 0: spin = '-'; break;
case 1: spin = '\\'; break; // NOTE: we had to escape our escape
case 2: spin = '|'; break;
case 3: spin = '/'; break;
}
// print it out:
std::cout <<"\rTime since start: " <<dag <<" days " <<(int)t <<" hours "
<<(int)min <<" minutes " <<(int)sek <<" seconds (" <<spin <<") "
<<std::flush;
//wait:
usleep(0.25 * 1000000); // do nothing for 0.25 seconds (takes time in micro-seconds)
#ifdef _WIN32 // windows is only accurate to the millisecond XDDD
Sleep(0.25 * 1000);
#else
usleep(0.25 * 1000000);
#endif
}
int main(){
// infinite loop (rolls over after reaching the limit of `unsigned int` )
for (unsigned int day = 0; 1; day++)
for (unsigned char hr = 0; hr < 24; hr++)//24 hours in a day
for (unsigned char min = 0; min < 60; min++)//60 minutes in an hour
for (unsigned char sec = 0; sec < 60; sec++)//60 seconds in a minute
for (unsigned char quarterSec = 0; quarterSec < 4; quarterSec++)//quarter seconds for the spinner.
printTimeCR(day, hr, min, sec, quarterSec);
}