Timer along with a c++ program.

I intend to make a simple minesweeper i am done with the most part but i am stuck at one place. I want to add a timer in it. The user will have 5 or 10 minutes to play. I used the function below for this purpose but it won't do the job as it wont allow me to do other tasks. The loop will go on and not allow the user to do anything till then.
I want to see both of them work side by side. Like the timer don't interfere in the working of the program
1
2
3
4
5
6
7
8
9
10
  void timer(int timeleft)
{
	int counter=0;
	while(timeleft>0)
	{
	cout<<"timeleft is :"<<timeleft;
	timeleft--;
	Sleep(1000);
	}
}
You can use this system:
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <ctime> //for time()

int main()
{
    int startTime = time(0);

    //Do stuff

    int endTime = time(0);

    int deltaTime = endTime - startTime;
    return 0;
}


You can keep track of a totalTime variable, and every update add deltaTime to the total time. This way you should be able to do what you intend to do.
Registered users can post here. Sign in or register to post.