c++ - Clear terminal every second but leave minutes -
i have seconds , minute counter, similar timer. however, cannot number of minutes stay on screen.
int main() { int spam = 0; int minute = 0; while (spam != -1) { spam++; std::cout << spam << " seconds" << std::endl; sleep(200); system("cls"); //i still want system clear seconds if ((spam % 60) == 0) { minute++; std::cout << minute << " minutes" << std::endl; } //but not minutes } }
system("cls")
clear screen, each iteration of while
loop, whereas print minute
every minute or so.
you need print minute every iteration:
while (spam != -1) { spam++; if (minute) std::cout << minute << " minutes" << std::endl; std::cout << spam << " seconds" << std::endl; sleep(200); system("cls"); if ((spam % 60) == 0) { minute++; } }
here assume want print minute if it's not zero, hence if (minute)
.
fwiw: want reset spam
0
when update minute
, depends on you're doing. perhaps wish display number of seconds elapsed in total.
Comments
Post a Comment