im trying to create something similar to "lost in migration" as a project for my finals but im having trouble with the randomization and the timer
how do i run two do while independently of each other
timer should not disappear, and must keep running until time is up, must run independently
randomization must not affect timer
bugs imputing directional key does not display result
while (timer) once and go to the do while (randomization) and will keep looping at "randomize" and will not go back to the while (timer)
while (timer) is affected bu getch() and getche() pausing it
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<windows.h>
#include<time.h>
//******************************************//
// DEFAULT BUILT-IN CLOCK //
//******************************************//
void Wait(int seconds)
{
clock_t end wait;
endwait = clock () + seconds * CLK_TCK;
while (clock() < end wait) {}
}
//***********************************************************//
// DIRECTIONAL KEYS //
//***********************************************************//
#define LEFT 75
#define RIGHT 77
#define UP 72
#define DOWN 80
int rdtsc()
{
as m volatile("rdtsc");
}
int main()
{
char ans;
int image;
int loop=1;
int correct=0, total=0;
int sec=0, min=0;
//***********************************************************//
// TIMER //
//***********************************************************//
int x=1;
while(1==1)
{
Wait(1);
sec++;
if(sec==46)
{
loop=0;
}
printf("%i:%i\n\n", min, sec);
//***********************************************************//
// RANDOMIZED IMAGES //
//***********************************************************//
fflush(st din);
srand(rdtsc());
image=rand()%4;
do
{
if(image==0)
{
printf(">>IMAGE 1 CORRECT LEFT<<");
ans=getche();
if(ans==LEFT)
{
printf("\n\ncorrect!");
}
else
if(ans!=LEFT)
{
printf("\n\nwrong!");
}
}
else
if(image==1)
{
printf(">>IMAGE 2 CORRECT UP<<");
ans=getche();
if(ans==UP)
{
printf("\n\ncorrect!");
}
else
if(ans!=UP)
{
printf("\n\nwrong!");
}
}
else
if(image==2)
{
printf(">>IMAGE 3 CORRECT DOWN<<");
ans=getche();
if(ans==DOWN)
{
printf("\n\ncorrect!");
}
else
if(ans!=DOWN)
{
printf("\n\nwrong!");
}
}
else
if(image==3)
{
printf(">>IMAGE 4 CORRECT RIGHT<<");
ans=getche();
if(ans==RIGHT)
{
printf("\n\ncorrect!");
}
else
if(ans!=RIGHT)
{
printf("\n\nwrong!");
}
}
getch();
system("cls");
}
while(loop==1);
}
getch();
}