The user has 10 minutes to complete this quiz and it should terminate when 10 minutes(600 seconds) are over.
Currently the code to my knowledge starts a timer, prints a question, receives an answer and checks if the answer is correct, and after that, checks to see the time elapsed.
From debugging, it would seem that as long as I have not answered a question, the time continues to elapse past 10 minutes, where I want the program to terminate as soon as 10 minutes is reached. I dont know if that is possible.
I would prefer if the code would immediately terminate when 600 seconds end. Something in the nature of while (time > 600 sec) { execute code } I don't know if thats possible or what functions could assist in that.
srand(time(0));
int score = 0;
int QAnswered = 0;
//initializes 10 minute timer and tells user how long they have.
auto start = high_resolution_clock::now();
auto end = high_resolution_clock::now();
auto duration = duration_cast<seconds>(end - start);
cout << "Time Limit is 10 minutes\n" << endl;
//loops through all 10 questions
for (int k = 0; k < 10; k++) {
int y = rand() % 100; //random number 1-100 to pick a question out
cout << "Q." << k + 1 << " " << Q[y] << y << endl; //prints Question number and then Question
cout << "Please enter your answer" << endl;;
cin >> ans;
transform(ans.begin(), ans.end(), ans.begin(), ::toupper);
if ((ans == "T" || ans == "TRUE") && A[y] == "TRUE")
score++;
if ((ans == "F" || ans == "FALSE") && A[y] == "FALSE")
score++;
end = high_resolution_clock::now();
duration = duration_cast<seconds>(end - start);
if (duration.count() >= 600) {
cout << "Time Finished" << endl;
break;
}
}