I haven't run the above code, and I'm sure it would need some tweaking, (they usually do), but the idea:
#include <conio.h> //or windows.h
int main ()
time_t start, now;
int i, ok=0,seconds;
start = time (NULL);
printf ("How much is 2+2? ");
ok=scanf ("%d", &i);
now = start;
printf("Time remaining: );
now = time(NULL);
printf(" %d ", 5 - (now-start));
//use delay(), (Sleep() in MS Windows), to give a 1/5th of a
//second delay or so. The timer (and there are other ways to
//make a timer), should show the time (at 10,10), about 3-5 times
//per second. Since it's in the same spot each time, it looks good.
//then the cursor return immediately to 10,26, to get user's input.
//and naps just a bit.
end = time (NULL);
seconds = now - start;
if (seconds > 5)
printf ("Sorry, you were too slow.\n");
else if (i==4)
printf ("That's correct.\n");
1) always put the cursor into one of two place places, that will remain constant: the timers location, and the spot for user's input
2) use a sub second delay so the timer is being printed at least 3 times per second, but not more than 10 times per second.
3) Immediately after printing the time remaining, move the cursor back to the user's input location, and do the delay again.
This is "old school" and single threaded. Windows has new timers with better ways of doing this. I don't know about Linux and OSX, but they probably have better timers, as well.