0

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 >>

2
Contributors
2
Replies
3
Views
11 Years
Discussion Span
Last Post by Vincentjames501
0

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

0

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,

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.