Answer to Question #277210 in C++ for dind

Question #277210

Create a c++ quiz program, in this program it has a 10 questions that the user will answer. The program has the following functions:


A. It will show the message (Correct) if the the answer is correct and (Wrong) if the answer is wrong


B. It can compute the total score


C. If the user Failed in the quiz it will ask the user if he wants to retake the quiz. ( 6 is the passing rate)


   C1.1If he select Yes he will take the quiz again. 


   C1.2. If he select No the program will automatically closed.


   Extra 10 points: use system(“clear”) to clear the the previous data in the screenx


1
Expert's answer
2021-12-08T08:16:03-0500
#include <iostream>
int score = 0;
void correct(bool answer)
{
	if (answer)
	{
		std::cout << "Correct!" << std::endl;
		++score;
	}
	else
	{
		std::cout << "Wrong" << std::endl;
	}
}
void quiz()
{
	std::string capital, answer;
	std::cout << "Enter the capital of Ukraine: ";
	std::cin >> capital;
	correct(capital == "Kyiv");
	int result;
	std::cout << "Enter the result of 12 * 12: ";
	std::cin >> result;
	correct(result == 144);
	std::cout << "Enter the capital of Poland: ";
	std::cin >> capital;
	correct(capital == "Warsaw");
	std::cout << "Enter the result of 15 * 6: ";
	std::cin >> result;
	correct(result == 90);
	std::cout << "Enter the figure with 3 angles: ";
	std::cin >> answer;
	correct(answer == "triangle" || answer == "Triangle");
	std::cout << "Enter the longest river in the world: ";
	std::cin >> answer;
	correct(answer == "Nil");
	std::cout << "Holiday, celebrated on 25th of December: ";
	std::cin >> answer;
	correct(answer == "Christmas");
	std::cout << "Enter the result of 7 * 8: ";
	std::cin >> result;
	correct(result == 56);
	std::cout << "The highest mountain in the world: ";
	std::cin >> answer;
	correct(answer == "Everest");
	std::cout << "The highest mountain in Ukraine: ";
	std::cin >> answer;
	correct(answer == "Goverla" || answer == "Hoverla");
}




int main()
{
	std::string answer;
	while (true)
	{
		quiz();
		if (score < 6)
		{
			std::cout << "Do you want to retake? ";
			std::cin >> answer;
			if (answer == "Yes" || answer == "yes")
			{
				continue;
				system("clear");
			}
			
			else
				break;
		}
		else
		{
			std::cout << "Congratulations!" << std::endl;
			std::cout << "Your score is: " << score << std::endl;
			break;
		}
	}
	
	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog