#include "stdafx.h"
#include <stdio.h>
#include <iostream>
#include <time.h>
using namespace std;
using namespace System;
void wait ( int seconds )
{
clock_t endwait;
endwait = clock() + seconds * CLOCKS_PER_SEC ;
while (clock() < endwait) {}
}
void timer()
{
int n;
printf ("Start\n");
for (n=10; n>0; n--) // n = time
{
cout << n << endl;
wait (1); // interval (in seconds).
}
printf ("DONE.\n");
system("PAUSE");
}
int main ()
{
timer();
cout << "test" << endl; // run rest of code here.}
return 0;
}
I'm trying to create a timer in C++ which would run in the background. So basically if you'd look at the 'main block' I want to run the timer (which is going to count down to 0) and at the same time run the next code, which in this case is 'test'.
As it is now the next line of code won't be run until the timer has finished. How do I make the timer run in the background?
Thanks for your help in advance!