DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C++ (http://www.daniweb.com/forums/forum8.html)
-   -   Help With A Timer And Stopping It. (http://www.daniweb.com/forums/thread20938.html)

Vincentjames501 Mar 27th, 2005 3:00 am
Help With A Timer And Stopping It.
 
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 [code][/code] tags >>

Acidburn Mar 27th, 2005 8:26 am
Re: Help With A Timer And Stopping It.
 
perhaps using a while loop, it goes round until an external varible changes to 1? whilst x!= 1 or space or somethng?

Vincentjames501 Mar 27th, 2005 1:45 pm
Re: Help With A Timer And Stopping It.
 
Quote:

Originally Posted by Acidburn
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,


All times are GMT -4. The time now is 12:29 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC