Hey guys, can someone help me with a function subprogram or a set of statements that allow me to do something within a time limit. I want to create a self-regulated test such that:
cout <<"Press 'S' to start"<<endl;
cin >>ready;
while(!((ready == 's')||(ready == 'S')))
{
cout <<"Press 'S' to start"<<endl;
cin >>ready;
}
if((ready == 's')||(ready == 'S'))
while(time != 0) *this is the part I need*
{
//here we have the actual test
}
This is possible, but there's nothing in the standard library which will handle it for you. Timing depends on counting CPU clock cycles, which is very operating-system dependent.
const string ans = "41";
char opt,ready,conf;
string name,surn,answer;
int y,x = (time(0) + 120);
int main()
{
system ("title M220 Self Regulating Test");
cout <<" Welcome To The Self-Efficient Test Trial"<<endl;cout <<endl;
cout <<" Enter First Name"<<endl;cout <<endl;
cout <<" ";cin >>name;cout <<endl;
cout <<" Enter Surname"<<endl;cout <<endl;
cout <<" ";cin >>surn;cout <<endl;
cout <<" "<<name<<", are you ready to begin your M220 test? (Y/N)"<<endl;
cout <<" ";cin >>opt;
if((opt == 'Y')||(opt == 'y'))
{
cout <<" Please Note"<<endl;
cout <<" ***************"<<endl;cout <<endl;
cout <<" You Have 120 Seconds To Complete This Test"<<endl;
cout <<" ==========="<<endl;cout <<endl;
cout <<" Lets Begin !"<<endl;cout <<endl;
cout <<" Press `S' to Start"<<endl;
cout <<" ";cin >>ready;
while(!((ready == 'S')||(ready == 's')))
{
cout <<"Signal readiness by pressing `S'"<<endl;
cout <<" ";cin >>ready;
}
if((ready == 'S')||(ready == 's'))
{
while(x > y)
{
y = (time(0));
system("cls");
cout <<endl;cout <<endl;cout <<endl;cout <<endl;cout <<endl;cout <<endl;
cout <<" You Have 120 Seconds To Complete This Test"<<endl;cout <<endl;
cout <<" Question 1 - Given the system: "<<endl;
cout <<" ============ "<<endl;
cout <<endl;
cout <<" 3x - 2y + z = 1 "<<endl;
cout <<endl;
cout <<" 2x + y - 3z = 6 "<<endl;
cout <<endl;
cout <<" x + 2y + 2z = 0 "<<endl;
cout <<endl;
cout <<" Evaluate the determinant by expanding"<<endl;
cout <<" along the second row."<<endl;
cout <<endl;cout <<endl;
cout <<" Enter Answer "<<endl;
cout <<" Det. = ";cin >>answer;cout <<endl<<endl;
cout <<" Confirm Answer: ["<<answer<<"] ? (Y/N) (No Undo!!)"<<endl;
cout <<" ";cin >>conf;
while(!((conf == 'Y')||(conf == 'y')))
{
cout <<" Re - Enter Answer "<<endl;
cout <<" Det. = ";cin >>answer;
cout <<" Confirm Answer: ["<<answer<<"] ? (Y/N) (No Undo!!)"<<endl;
cout <<" ";cin >>conf;
}
if(answer == ans)
{
cout <<endl;
cout <<" Correct, Congradulations!!"<<endl;cout <<endl;
cout <<" Score : 98% "<<endl;
}
else
{
cout <<endl;
cout <<" Incorrect answer"<<endl;cout <<endl;
cout <<" Score : 0% "<<endl;
}
cout <<endl;
cout <<" End of Test"<<endl;cout <<endl;
system("pause");
}
}
}
It doesn't give an infinite loop. The loop will break after 120 seconds, if the conditions are evaluated after 120s.
-What you want is a break; for when the test is completed, so as to not run the test again.
-The timing to start only after they have entered their name and stuff.
***-Ideally, a separate thread running to constantly evaluate the time and to break the loop if the time is reached. This is very advanced stuff.
-More realistically, just to say the test was failed if y > x when the test is completed.
Yeah I see what you mean, that's the most probable thing to do. I was just wondering if I can actually do the statements while the time is counting down.
Can you shed some light on how to create the separate thread, I'm familiar enough with C++ t follow