C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old September 10th, 2006, 12:51 PM
costas costas is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 407 costas User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 3 h 25 m 24 sec
Reputation Power: 12
"Waiting" Problem

Hi everyone,

I'm making a program and in a certain stage I want to get a variable from the user, but with time limits. Here's part of my code:

Here's the part where I use my wait function.


Code:
            cout<<"Quickly press d\n";
	wait(2);
	if (button == 'd')
	{.....
             }


Now the part where I initialize the wait function:

Code:
void wait ( int seconds )
{
  clock_t endwait;
  endwait = clock () + seconds * CLK_TCK ;
  while (clock() < endwait) {
	  cin>>button;
  }
}


It won't work though! If anyone could help, it'd be great!!

Thanks in advance!!

Note: I've included time.h .

Costas

Reply With Quote
  #2  
Old September 10th, 2006, 03:44 PM
ubergeek ubergeek is offline
Contributing User
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jan 2005
Posts: 600 ubergeek User rank is Private First Class (20 - 50 Reputation Level)ubergeek User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 22 h 40 m 27 sec
Reputation Power: 14
Send a message via AIM to ubergeek
So, you need to get a keypress from the user without waiting for an enter press. This will be different depending on your operating system and compiler. This GIDForums thread may be helpful.

Good luck!

Reply With Quote
  #3  
Old September 11th, 2006, 03:49 AM
costas costas is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 407 costas User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 3 h 25 m 24 sec
Reputation Power: 12
Hey thanks, but it requires some header files, which I don't have. I'll try to find them, thanks anyway though!

Costas

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > "Waiting" Problem


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap