I would like to create a program that imposes a time limit user, so the user will need to input any answer before 10 seconds. If the user doesn't enter a variable before the time limit, I'd like to interrupt the cin>>variable function ( or possibly something else that works just as well), when the user takes more than 10 seconds, so I can display a message, telling the user that he took too long.
#include <time.h>
#include <iostream>
using namespace std;
unsigned int difference ( unsigned int &start_time, unsigned int &end_time )
{
end_time = clock();
return ( ( end_time - start_time ) /1000 );
}
int main ()
{
unsigned int start_time = clock();
unsigned int end_time;
int variable;
while ( difference ( start_time, end_time) < 10 )
{
cout<< difference ( start_time, end_time) << endl;
cin >> variable;
}
}

New Topic/Question
Reply



MultiQuote





|