#include <iostream>
#include <cstdlib>
usingnamespace std;
int t=0; //timer
int main()
{
int r; //random number
int x; //input for random number
char a;//play again
int s; //score
s=0;
a='y'; //sets play again to yes
int h; //picks between letter and number
int to; //starting time
int tf; //ending time
char y;
cout<<"This program will test your reflexes.\nSimply copy the number or letter shown as fast as you can.\n but be careful, you only have 1 seccond to answer.\n If you can survive for 60 seconds, you win."<<endl;
while (a=='y')
{
h=(rand() % 3);
if (h==2)
{
h=(rand() % 3);
r=(rand() % 10);
cout << r << "\n";
to=t;
cin >> x;
tf=t;
if (x!=r || (x!=1 && x!=2 && x!=3 && x!=4 && x!=5 && x!=6 && x!=7 && x!=8 && x!=9 && x!=0) || tf-to>1)
{
cout <<"FAILURE your score was "<<s<<endl;
cout <<"\ntry again? (y/n)"<<endl;
s=0;
cin>>a;
}
else
{
if (t<60)
{
s=s+1;
cout <<"\nyour current score is "<<s<<endl;
cout <<"time left:"<<60-t<<endl;
}
else
{
s=s+1;
cout <<"\nyou win. Your final score is"<<s<<endl;
}
}
}
else
{
h=(rand() % 3);
char ch = 'a' + rand() % (('z'-'a') + 1);
cout << ch << "\n";
to=t;
cin >> y;
tf=t;
if (y!=ch || tf-to>1)
{
cout <<"FAILURE your score was "<<s<<endl;
cout <<"\ntry again? (y/n)"<<endl;
s=0;
cin>>a;
}
else
{
if (t<60)
{
s=s+1;
cout <<"\nyour current score is "<<s<<endl;
cout <<"time left:"<<60-t<<endl;
}
else
{
s=s+1;
cout <<"\nyou win. Your final score is"<<s<<endl;
}
}
}
}
return 0;
}
int time() //increases t by one every second
{
for(;;)
{
t++;
sleep(1);
}
return 0;
}