Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Dec 3rd, 2004, 4:12 PM   #1
RosdaHale
Newbie
 
Join Date: Nov 2004
Posts: 15
Rep Power: 0 RosdaHale is on a distinguished road
In my program i need a time limit for the user to input as answer. (the user input will be an integer or a char value), how do i go about putting the cin statement In to a timed state, if the user answers the question in the time then.....if not then........
RosdaHale is offline   Reply With Quote
Old Dec 3rd, 2004, 4:27 PM   #2
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
This should put you on the right direction:

The functions you are looking for are part of time.h, be sure
to include that header file.


/* clock example: countdown */
#include <stdio.h>
#include <time.h>

void wait ( int seconds )
{
 *clock_t endwait;
 *endwait = clock () + seconds * CLK_TCK;
 *while (clock() < endwait) {}
}

int main ()
{
 *int n;
 *printf ("Starting countdown...\n");
 *for (n=10; n>0; n--)
 *{
 * *printf ("%d\n",n);
 * *wait (1);
 *}
 *printf ("FIRE!!!\n");
 *return 0;
}

Output:
Starting countdown...
10
9
8
7
6
5
4
3
2
1
FIRE!!!


Also look at:

/* difftime example */
#include <stdio.h>
#include <time.h>

int main ()
{
 time_t start,end;
 char szInput [256];
 double dif;

 time (&start);
 printf ("Please, enter your name: ");
 gets (szInput);
 time (&end);
 dif = difftime (end,start);
 printf ("Hi %s.\n", szInput);
 printf ("You have taken %.2lf seconds to type your name.\n", dif );
 
 return 0;
}
__________________
http://jasonpowers.net

"There are a thousand hacking at the branches of evil to one who is striking at the root."
Infinite Recursion is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:41 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC