How to display a timer simultaneously with the rest of the program in c++?

  c++, clock, ctime, multithreading, timer

So I’ve been making a terminal-based quiz as my first-year project, I decided to display a timer along with the code, but the timer doesn’t let the program proceed cause of the infinite loop used in the timer.

How do I proceed through this problem?

    void timer()
{
    while (true) {
        clock_display();//Function loaded with manipulators to just show the 00:00:00 interface 
        sleep(1);
        sec++;
        if (sec == 60) {
            mins++;
            if (mins == 60) {
                hrs++;
                mins = 0;
            }
            sec = 0;
        }
    }
}

int main(){
     timer();
     //Other code I have to run
}

Source: Windows Questions C++

LEAVE A COMMENT