-
Notifications
You must be signed in to change notification settings - Fork 0
/
decimal.cpp
72 lines (72 loc) · 2.77 KB
/
decimal.cpp
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
60
61
62
63
64
65
66
67
68
69
70
71
72
/*==============================================================================*
* please read the README.md file *
* *
* to compile and run use: *
* clear;g++ decimal.cpp -o decimal; "/home/test/Downloads/clock/"decimal *
*=============================================================================== */
#include <iostream>
//#include <unistd.h>
#include <ctime>
int main() {
std::cout<<"| \tDecimal \t"<<"| \tStandard\t"<<"| \tClock \t\t|\n";
std::cout<<"|======================="<<"|======================="<<"|=======================|\n";
//declare counters
long duration,std_sec,dec_sec,std_min,std_hr,dec_min,dec_hr;
std_sec=0,dec_sec=0;std_min=0;dec_min=0;std_hr=0;dec_hr=0;duration=0;
//declare timers
std::clock_t start,std_start,dec_start,current;
start,std_start= std::clock();
dec_start= std::clock();
//while loop for given clock cycles
while (true){
//set current time and elapsed time
current = std::clock();
duration =(current-start);
//increment standard time
if(current-std_start >=CLOCKS_PER_SEC){
std_start = std::clock()-(CLOCKS_PER_SEC-(current-std_start));
if(std_sec==60){
std_sec=0;
if(std_min==60){
std_min=0;
if(std_hr==24){
std_hr=0;
}else{
std_hr++;
}
}else{
std_min++;
}
}else{
std_sec++;
}
}
//increment decimal time
if(current-dec_start >=864000){
dec_start = std::clock()-(864000-(current-dec_start));
if(dec_sec==100){
dec_sec=0;
if(dec_min==100){
dec_min=0;
if(dec_hr==10){
dec_hr=0;
std::cout<<"NEW DAY\n";
}else{
dec_hr++;
}
}else{
dec_min++;
}
}else{
dec_sec++;
}
//print time in columns
std::cout<<"| Decimal: "<<dec_hr<<":"<<dec_min<<":"<<dec_sec<<"\t|";
std::cout<<" Standard: "<<std_hr<<":"<<std_min<<":"<<std_sec<<"\t| Clock: "<<duration<<" \t|\n";
}
//sleep(20);
}
//std::cout<<"|======================="<<"|======================="<<"|=======================|\n";
//std::cout<<"| \tDecimal \t"<<"| \tStandard\t"<<"| \tclock \t\t|\n";
return 0;
}