I have this simple program in c that I'm supposed to add a countdown timer. The program must print the amount of time left for the user (player) every second.
int main()
{
int num, random_genNo;
int count = 0;
random_genNo = rand()%100;
while(1) {
count++;
printf("deviner le nombre entre 0 et 100\n");
scanf("%d",&num);
if(random_genNo==num) {
printf("felicitation, vous avez devinez le numero correcte.\n");
printf("nombre de coups %d", count);
break;
} else if(random_genNo<num) {
printf("numero a deviner est inferieur a votre numero, ressayer...\n");
} else if(random_genNo>num) {
printf("numero a deviner est superieur a votre numero, ressayer...\n");
}
}
return 0;
}
I thought about transforming the whole program to a state machine with a uchar Counter decrementing every second but i faced a lot of problems. So I created a state machine that only does the countdown timer. The rest of the program is in the main but got the same issue.
I think it may have a better way to approach this. Any idea?