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

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -