hi guys!!
i am wrting a program for a small arithemtic game,it displays two numbers and ask user to enter the sum of these two numbers,the program runs fine but i want to add a countdown timer,i mean time limit for user to answer all 10 questions within 30 seconds.i hav tried everything but dint came up with any idea
it should display the timer and questions.plzz help i am new to programming
void addtion()
{
int firstran,secondran,num1,num2,sum,in1,ans,count=0,right=0,worng=0,score=0;
cout<<"\t\t\t\tADDTION\n";
for(int k=0;k<80;k++)
{
cout<<"-";
delay1();
}
cout<<"\n\nREADY????";
delay1();
cout<<"\n\nENTER A CHAR WHEN READY.....\n";
cin>>in1;
system("cls");
cout<<"\t\t\t\tLEVEL 1\n";
////print lines----------------------------------
for(int i=0;i<80;i++)
{
cout<<"-";
delay1(); //delay to print cgar by char
}
cout<<"\t\t\t\tADDTION\n";
for(int k=0;k<80;k++)
{
cout<<"-";
delay1();
}
//////////--------------------------------------
cout<<"\nGO!!\n";
for(int i=10;i>0;i--)
{
firstran=random();
num1=gennumber(firstran); ///generate two random numbers for addtion//////
secondran=random2(num1); //gennumer generates number within 99 for level 1///
num2=gennumber(secondran);
count++;
sum=num1+num2;
cout<<count<<" -> "<<num1<<" + "<<num2<<" = ";
cin>>ans;
if(ans==sum)
{
right++;
score=score+10;
}
else { worng++;}
}
results(right,worng,score); ////prints the result to std output///
getinfo(score); ///get player name and store it in file with scores////
viewscores(); ///read names from the file and display it on std output///
}
i have used clock() function the program runs good,but i want to display the time at the corner of the screen and also display the questions at the same time
is there any way to do that??
Mmmm... This may be tricky... I'm afraid you'll have to resort to multithreading. Have a main thread that displays the questions and gets the answers and another one that handles the clock. You may also have to use some windows API to change the position of the console cursor.