Quiz maker
Using if statements; Make a multiple answers quiz that asks the user questions adds to a score when they get the question right.
Output the total score at the end of the quiz.
Here are some sample questions you can use:
Q: How many planets are there in our solar system?
1: 2 planets 2: 21 planets 3: 8 planets
Q: What colour is an orange
1: Red 2: Orange 3: Green
Q: How many players are there in a football team?
1: 4 players 2: 68 players 3: 11 players
Hint
Declare a variable to keep track of the score. Assign 0 to it and increment it by 1 for every correct answer.
When prompting the user for an answer, label each answer with a number. That way, the user can input the number to refer to the answer.
Use an if statement and a comparrison operator (==) to check if the answer the user gave is correct.
Answer
#include <iostream>
int main() {
// This is the variable we use to keep track of how many questions the user has answered correctly
int score = 0;
std::cout << "Quiz-time!\n";
int answer1;
std::cout << "How many planets are there in our solar system?\n";
std::cout << "1: 2 planets\n";
std::cout << "2: 21 planets\n";
std::cout << "3: 8 planets\n";
std::cin >> answer1;
if (answer1 == 3)
score += 1;
int answer2;
std::cout << "What colour is an orange\n";
std::cout << "1: Red\n";
std::cout << "2: Orange\n";
std::cout << "3: Green\n";
std::cin >> answer2;
if (answer2 == 2)
score += 1;
int answer3;
std::cout << "How many players are there in a football team?\n";
std::cout << "1: 4 players\n";
std::cout << "2: 68 players\n";
std::cout << "3: 11 players\n";
std::cin >> answer3;
if (answer3 == 3)
score += 1;
std::cout << "Your scored: " << score << "/3 \n";
}