+ 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
8 Antworten
+ 1
it was for testing. it can be any value. That value determines how many seconds it will run.
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
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;
}
}
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;
}
}
}
}
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
0
use Sleep () from windows.h ... the number you input in sleep is the time it waits in milliseconds....
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;
}
}
}
}
0
why the value122