The quiz program is an illustration of loops and conditional statements
- Loops are used to perform repetition
- Conditional statements are used to make decisions
<h3>The quiz program</h3>
The quiz program written in C++, where comments are used to explain each action is as follows:
#include <iostream>
using namespace std;
int main(){
//This prints the instruction
cout<<"Enter T/t for True; F/f for False\n";
//This initializes the question
string questions[5] = { "Q1", "Q2", "Q3", "Q4", "Q5"};
//This initializes the correct options
char options[5] = { 'T','T','F','F','T'};
//This declares the user response
char opt;
//This initializes the score to 0
int score = 0;
//This loop is repeated 5 times
for (int i = 0; i < 5; i++){
//This prints the current question
cout << i + 1 <<". "<<questions[i]<<"\nAnswer: ";
//This gets the user response
cin>>opt;
//If the user response is correct
if(toupper(opt) == options[i]){
//The score is incremented by 2
score+=2;
}
}
//This prints the total score
cout<<"Score: "<<score;
return 0;
}
Read more about loops at:
brainly.com/question/19347842