I am writing a simple program to help my niece learn her multiplication tables. To prevent her from taking too long, I want to use a timer which, after a set amount of time passed, will cause the program to skip to the next question automatically without her inputting anything. If the program then does this, it will increment a counter which shows how many times she ran out of time, something like this:
if(table_to_test == 2)
{
finish = clock() + time_to_complete;
++tries;
printf("2 x 8 = ");
scanf("%d", &answer);
if(answer == 16 && (clock() < finish))
{
printf("Correct!\n");
++amount_correct;
}
else if(answer != 16 && (clock() < finish))
{
printf("\aWrong!\n");
}
else if(clock() > finish)
{
printf("\aTime's up!\n");
++ran_out_of_time;
}
}
finish is how long she has before the timer skips to the next question, and time_to_complete is what the user input's for how long the program gives you before automatically skipping to the next question.
Whenever I run this, no matter how quickly I enter the answer, the program outputs the "Time's up!" line.
time_to_complete and finish are of type int