![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Nov 2004
Posts: 15
Rep Power: 0
![]() |
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........
|
|
|
|
|
|
#2 |
|
Programming Guru
![]() ![]() ![]() |
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." |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|