我目前正在制作测验计划。我创建了一个倒计时,但是随着c ++逐行行动,我得到了我想要的东西。我希望倒计时与测试同时进行。
这是我的程序的一部分
void QUIZ::OOP2()
{
system("cls");
QUIZ("OOP2");
int oop2_time = 100;
for (int i = oop2_time; oop2_time >= 0; i--)
{
cout << "\t\t\tQuestions of OOP2\n\n";
line();
cout << "1. Switch selection structure can be used to represent any kind of if-else selection structure? \n";
line();
cout << " a) True b) False \n";
CorrectB(var);
if (oop2_time == 100)
{
cout << "You have the remaining" << oop2_time << "seconds \n" << endl;
Sleep(40000);
}
if (oop2_time == 60)
{
cout << "You have the remaining" << oop2_time << "seconds \n" << endl;
Sleep(30000);
}
if (oop2_time == 30)
{
cout << "You have the remaining" << oop2_time << "seconds \n" << endl;
Sleep(15000);
}
if (oop2_time == 15)
{
cout << "You have the remaining" << oop2_time << "seconds \n" << endl;
Sleep(10000);
}
if (oop2_time == 5)
{
cout << "You have the remaining" << oop2_time << "seconds \n" << endl;
Sleep(5000);
cout << "\nTime is out\n";
goback();
intro();
}
result("OOP2");
goback();
}
}
答案 0 :(得分:0)
不使用多线程或std :: chrono而只使用基本代码,这里是一段代码片段。我使用了递归函数和1秒的时间分辨率。通过设置init(place:FromPlaceOrToPlace){
if let fromPlace = place as? FromPlace {
print(fromPlace.name)
print(fromPlace.id)
} else if let toPlace = place as? ToPlace {
print(toPlace.name)
print(toPlace.id)
}
}
:
stop = true;