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
#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;
}
Comments
Leave a comment