+ 1

How to make a counter that pretty much counts time and prints it in c++

Make it so it like prints: 0:01 or 1second 0:02 or 2seconds ... 1:25 or 1 minute 25 seconds

27th Jun 2016, 5:14 PM
Armandas Bolevičius
Armandas Bolevičius - avatar
8 Antworten
+ 1
it was for testing. it can be any value. That value determines how many seconds it will run.
28th Jun 2016, 9:11 AM
Armandas Bolevičius
Armandas Bolevičius - avatar
0
may be two loops may help one inside another but addition of the value is very fast so equivalent to a second is very hard to obtain
27th Jun 2016, 5:23 PM
Infinity
Infinity - avatar
0
for(int i=0;i<60;i++){ for(int j=0;j<60;j++){ if(j>10) cout<<i<<":"<<j<<endl; else cout<<i<<":0"<<j<<endl; } }
27th Jun 2016, 5:41 PM
ali
0
is that accurate to real time? also why does this only output: 1 2 3 4 5 #include <iostream> #include <ctime> using namespace std; int main() { int timer = 0; int b = 0; while (timer<62) { b = 0; int x=time(0); int a=time(0); while (x<=a && !b==1) { a = time(0); if (x<a) { timer = timer+1; cout << timer << endl; b = 1; } } } }
27th Jun 2016, 5:43 PM
Armandas Bolevičius
Armandas Bolevičius - avatar
0
I won't get accurate to real time as the program doesn't adds the variable one second at a time therefore it is hard to obtain a real time by the help of loop
27th Jun 2016, 6:28 PM
Infinity
Infinity - avatar
0
use Sleep () from windows.h ... the number you input in sleep is the time it waits in milliseconds....
28th Jun 2016, 6:16 AM
Mukul Kumar
Mukul Kumar - avatar
0
i got it nvm #include <iostream> #include <ctime> using namespace std; int main() { int timer = 0; int b = 0; int cancel = 0; int min = 0; while (cancel<122) /* 122 is how many seconds it will execute */ { b = 0; int x=time(0); int a=time(0); while (x<=a && !b==1) { a = time(0); if (x<a) { timer = timer+1; cancel = cancel + 1; if (timer < 60) { if (timer < 10) { cout << min << ":0" << timer << endl; } else { cout << min << ":" << timer << endl; } } else { min = min + 1; timer = timer % 60; if (timer < 10) { cout << min << ":0" << timer << endl; } else { cout << min << ":" << timer << endl; } } b = 1; } } } }
28th Jun 2016, 8:47 AM
Armandas Bolevičius
Armandas Bolevičius - avatar
0
why the value122
28th Jun 2016, 8:49 AM
Infinity
Infinity - avatar