Click here to Skip to main content
15,893,594 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am currently making a quiz program. And I created a countdown, but as c++ does actions line by line I am getting what I want. I want countdown work simultaneously with the tests.

What I have tried:

here is the one part of my program

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.	Evaluate !(1 && !(0 || 1)) \n";
		line();
		cout << "A)True \t B) False \t C)Error\t D)None of these\n";

		CorrectA(var);

		_getch(); system("cls"); line();
		cout << "2.Cout<<((4*2/2)%2); will display\n";
		line();
		cout << "a) 4    b) 2      c) 0     d)  1\n";

		CorrectC(var);

		_getch(); system("cls"); line();
		cout << "3.___________ is a NOT a valid identifier     \n";
		line();
		cout << "  a)  num2   b) while        c) my_number  d) INT \n";

		CorrectB(var);

		_getch(); system("cls"); line();
		cout << "4.The precedence of athematic operators is (highest to lowest from left to right)?  \n";
		line();
		cout << "	a) %,  *, / , +    b). *, +, /,%     c).  %, +, *,  /    d). %, *, +, / \n";

		CorrectB(var);

		_getch(); system("cls"); line();
		cout << "5. Which operator has the highest priority (precedence) \n";
		line();
		cout << " a)  *         b)  +          c) ( )   d) /  \n";

		CorrectA(var);

		_getch(); system("cls"); line();
		cout << "6.The keyword "default "  can be written anywhere in switch block \n";
		cout << "   a)  True       b)  False \n";
		line();

		CorrectA(var);

		_getch(); system("cls"); line();
		cout << "7. Break statement is used for \n";
		line();
		cout << "  a). Quit the current block   b)  Quit a program  c) return 0    d) None    \n";

		CorrectA(var);

		_getch(); system("cls"); line();
		cout << "8.int k=‘K’;  cout << k ;  will display        \n";
		line();
		cout << "    a) K        b)  ASCII code of K               c) k           d)    garbage value  \n";

		CorrectB(var);

		_getch(); system("cls"); line();
		cout << "9.  The program that translates high-level language program into object code       is called  \n";
		line();
		cout << "	 a) Editor   b) Assembler         c) Decoder    d) Compiler  \n";

		CorrectD(var);

		_getch(); system("cls"); line();
		cout << "10.  If you are required to declare a variable to store the marks of a student in OOP subject (Min 0~ Max 100), which data type will you choose to use the memory efficiently?     \n";
		line();
		cout << " a)  short    b) unsigned int   c) float   d) int    \n";

		CorrectA(var);

		_getch(); system("cls"); line();
		cout << "11. 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();
	}
}
Posted
Updated 15-Apr-18 6:40am
v2
Comments
[no name] 15-Apr-18 11:36am    
And the problem/question is?
Member 13780562 22-Apr-18 12:10pm    
the question is written. Can i run two processes at the same time?
KarstenK 15-Apr-18 13:59pm    
tip: use a else in the following if, or a switch (with a default).

1 solution

As you noted, cin operations block their thread of execution. You need to countdown in a separate thread.
 
Share this answer
 
Comments
Member 13780562 16-Apr-18 18:05pm    
but i didn't cover that yet, is there any other ways
CPallini 17-Apr-18 3:10am    
Nope, as far as I know.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900