I am writing a multiplication table program to help my niece learn. I want her to be able to have a set amount of time to answer each question (hence the for loop which acts as a delay). The delay works, as after delay seconds the program outputs 'Time's up'! However, the program still waits for me to input a value and press enter before it evaluates answer and checks if it is 'correct' or 'wrong'(this isn't fixed by putting the printf and scanf after the for loop together inside the loop). I know the delay just waits a few seconds and then continues as normal, which is why I need to input a number and press enter. However, I don't know how to get around this.
Basically, I want the program to automatically 'enter' if delay seconds has passed and she hasn't entered a value, resulting in the answer being 'wrong'. But if she enters a value and presses enter before the delay seconds is over, I want to still check if it is either 'correct' or 'wrong'. I have searched for other means of doing this but I simply can't get it right. This is the code so far (again, I know the for loop delay only lets the program wait delay seconds before continuing normally, but I don't know to get around this.
time_t start_time = 0;
int delay = 0;
int answer = 0;
int correct = 0;
int wrong = 0;
printf("How long should the delay be?:\t");
scanf("%d", &delay);
start_time = clock();
printf("\n2 x 4 =\t");
for( ;clock() - start_time <= delay*CLOCKS_PER_SEC; );
printf("\n\nTime's up!\n\n");
scanf("%d", &answer);
if(answer == 8)
{
printf("\nCorrect!\n");
++correct;
}
else if(answer != 8)
{
printf("\n\aWrong!\n");
++wrong;
}
EDIT: I am running Windows and using CodeBlocks with mingw32. I just want the program to be a simple .exe file which will run through CMD. (It does that already though).