Hi all, I'm trying to make a very simple reaction game where a random number flickers on the screen for a fraction of a second and the user has to then enter the number before another comes on the screen after a random amount of time. However I dont know how i would make it so that the user cannot enter anything after a certain amount of time has passed, below is my code, could someone give me a hand? Also FYI, clock_start is at 5100 because by the time the program actually gets to scanning in the first number the time is at an absolute minimum of 5050 milliseconds however obviously this is an impossible number to reach due to processing, my machine clocks in at 5080.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <windows.h>
int main(void)
{
int i;
int random_number;
int input, score = 0;
int clock_start = 5100;
system("cls");
printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
printf("\t\t\t WELCOME TO REACTION\n");
Sleep(2000);
for(i=3;i>0;i--)
{
system("cls");
printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
printf("\t\t\t\t %d", i);
Sleep(1000);
}
srand(time(0));
for(i=0;i<10;i++)
{
random_number = rand() % 1000;
system("cls");
printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
printf("\t\t\t\t %d\n", random_number);
Sleep(50);
system("cls");
printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
printf("\t\t\t\t ");
clock();
//this is the part im not getting
///////////////////
if(clock() < clock_start + 3000)
{
scanf("%d", &input);
}
else if(clock () > clock_start + 3000)
{
printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
printf("\t\t\t\tTOO LATE!");
Sleep(1000);
}
//////////////////////
system("cls");
Sleep(1000);
if(input == random_number)
{
score++;
}
}
printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
printf("\t\t\t\tYour overall score is %d", score);
printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
}