Hey Guys, im trying to create a timer in c++ that starts at one, and every second the program displays the next number starting from -15, i have the start, but what i want is a breaker button... Such as while its counting, i want to be able to press either the space, enter, 1, or 0 button on the keyboard to break the timer and then display the timers current value.
Heres What I Have So Far. (Note: my script is far longer than this and so some of my #includes are necessary that you don't see)
___________________________

#include <iostream>
#include <stdlib.h>
using namespace std;
#include <cmath>
#include <windows.h>
#include <mmsystem.h>

void main()
{
cout <<"\n\nPress 1 Then Enter To Begin: ";
int anykey;
cin >> anykey;

if (anykey)
{
int timer = -15;
while (timer < 45)
	{
		cout <<++timer <<", ";
			Sleep(1000);
			int key;
			cin >> key;
				switch(key)
				{case 1:
				cout <<"Your Time Was: " << timer;}
}

_________________________

If Anyone Can Help.... Please Do :-P

Thanks!


<< moderator edit: added

tags >>

perhaps using a while loop, it goes round until an external varible changes to 1? whilst x!= 1 or space or somethng?

perhaps using a while loop, it goes round until an external varible changes to 1? whilst x!= 1 or space or somethng?

Prehaps you can give me an example as to I am still confused. How do I give the user the ability to press a button while a operation (the timer counting) is going? If you or anyone else can kinda alter this script and post it, I would be sincerly greatful.

Thanks,

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.