Help With A Timer And Stopping It.

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2005
Posts: 6
Reputation: Vincentjames501 is an unknown quantity at this point 
Solved Threads: 0
Vincentjames501 Vincentjames501 is offline Offline
Newbie Poster

Help With A Timer And Stopping It.

 
0
  #1
Mar 27th, 2005
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)
___________________________
  1. #include <iostream>
  2. #include <stdlib.h>
  3. using namespace std;
  4. #include <cmath>
  5. #include <windows.h>
  6. #include <mmsystem.h>
  7.  
  8. void main()
  9. {
  10. cout <<"\n\nPress 1 Then Enter To Begin: ";
  11. int anykey;
  12. cin >> anykey;
  13.  
  14. if (anykey)
  15. {
  16. int timer = -15;
  17. while (timer < 45)
  18. {
  19. cout <<++timer <<", ";
  20. Sleep(1000);
  21. int key;
  22. cin >> key;
  23. switch(key)
  24. {case 1:
  25. cout <<"Your Time Was: " << timer;}
  26. }
_________________________

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

Thanks!


<< moderator edit: added [code][/code] tags >>
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 489
Reputation: Acidburn is an unknown quantity at this point 
Solved Threads: 5
Acidburn Acidburn is offline Offline
Posting Pro in Training

Re: Help With A Timer And Stopping It.

 
0
  #2
Mar 27th, 2005
perhaps using a while loop, it goes round until an external varible changes to 1? whilst x!= 1 or space or somethng?
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 6
Reputation: Vincentjames501 is an unknown quantity at this point 
Solved Threads: 0
Vincentjames501 Vincentjames501 is offline Offline
Newbie Poster

Re: Help With A Timer And Stopping It.

 
0
  #3
Mar 27th, 2005
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,
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC