0
Is there any simpler way to move one step in loop after some time?
I will ask a user a question and if he is unable to answer the question within 30 second,I have to display another question and continue the timer for every question till file reads all the questions.
12 Respostas
+ 1
Before start the input store current time in a variable "startTime".
And after the input, just before register it. Also get a current time, then do a simple calculation (currentTime-startTime) to get how much time user takes to finish an input. If its more than specified time then dont process the input
+ 1
unsigned long startTime = time(NULL);
//input
unsigned long endTime = time(NULL);
if((endTime-startTime)>(second*1000))cout<<"no good";
0
Idk if you can cancel console input in c++.
But the timer need to run in different thread, so it wont intercept the input.
Here's a good resource about thread
http://www.cplusplus.com/reference/thread/thread/
It has an example, dont worry.
As for the countdown maybe you can call sleep inside the timer thread, to make it stop for cetain amount of time
0
Taste I've not studied tread yet and i tried sleep function but it nust block the whole program for certain amount of time..I don't want a program to block but want to continue without the user input after sometime
0
Thats why you need to put sleep inside another thread, so it wont block the main thread
for the user input there's a trick, create a variable lets call it "timeout" set it to false. after the timer runs out set it to true. and after user input check "timeout" first before register the input
0
Taste can we do it without thread as I'm not allowed to do the project out of my course outline :/
0
Okay, what about storing current time ? Is it allowed ?
0
Taste yes..can you elaborate how can I do it?
0
ok I'll try this out Taste thank you
0
Taste do we not have to register the input to get the "current time"? or in other words, how will it calculate the time before the user input ?
0
Save it, before cin
0
Taste can you give me a sample code..I am still not getting the point