Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hi, i want to write a code for a simple quiz which has 3 multiple choices&2 true

ID: 3542688 • Letter: H

Question

Hi, i want to write a code for a simple quiz which has 3 multiple choices&2 true/false questions,I'm a beginner c++ so i need the code to be very simple using IF and while loops and structure if needed etc..i've posted the question below.. "Write an application that creates a quiz that contains at least five questions about a hobby, popular music, astronomy, or any other personal interest. Each question can be multiple choice (for which valid responses are a, b, c, or d), or true/false (for which valid responses are t and f ). If the user responds to a question with an invalid character, display an error message and prompt the user again. If the user answers the question with a valid and correct response, display an appropriate message. If the user responds to a question with a valid but incorrect response, display an appropriate message as well as the correct answer. At the end of the quiz, display the number of correct and incorrect answers."

Explanation / Answer

#include<iostream>
using namespace std;
int main()
{
int incorrect = 0;
char response;
cout <<"Question 1: which of following is a not hobby: " << endl;
cout <<"a.stamp collection b. cycling c.watching movies d.killing " << endl;
cin>> response;
while(response!='a' && response!='b' && response!='c' && response!='d')
{
cout <<"Invalid respose entered. enter response again " << endl;
cout <<"a.stamp collection b. cycling c.watching movies d.killing " << endl;
cin>> response;
}
if(response=='d')
cout <<"correct answer" << endl;
else
{
incorrect++;
cout <<"You have chosen wrong answer. correct answer is option d." << endl;
}
cout <<"Question 2: who is not singer : " << endl;
cout <<"a.shakira b. michael jackson c.britney spears d.ashok " << endl;
cin>> response;
while(response!='a' && response!='b' && response!='c' && response!='d')
{
cout <<"Invalid respose entered. enter response again " << endl;
cout <<"a.shakira b. michael jackson c.britney spears d.ashok " << endl;
cin>> response;
}
if(response=='d')
cout <<"correct answer" << endl;
else
{
incorrect++;
cout <<"You have chosen wrong answer. correct answer is option d." << endl;
}
cout <<"Question 3: which of following is a planet : " << endl;
cout <<"a.loki b. stark c. hulk d.earth " << endl;
cin>> response;
while(response!='a' && response!='b' && response!='c' && response!='d')
{
cout <<"Invalid respose entered. enter response again " << endl;
cout <<"a.loki b. stark c. hulk d.earth " << endl;
cin>> response;
}
if(response=='d')
cout <<"correct answer" << endl;
else
{
incorrect++;
cout <<"You have chosen wrong answer. correct answer is option d." << endl;
}
cout <<"Question 4:are humans are mammals : " << endl;
cout <<"true or false" << endl;
cin>> response;
while(response!='t' && response!='f')
{
cout <<"Invalid respose entered. enter response again " << endl;
cout <<"true or false" << endl;
cin>> response;
}
if(response=='t')
cout <<"correct answer" << endl;
else
{
incorrect++;
cout <<"You have chosen wrong answer. correct answer true." << endl;
}
cout <<"Question 5:dogs live more than tortoise. : " << endl;
cout <<"true or false" << endl;
cin>> response;
while(response!='t' && response!='f')
{
cout <<"Invalid respose entered. enter response again " << endl;
cout <<"true or false" << endl;
cin>> response;
}
if(response=='f')
cout <<"correct answer" << endl;
else
{
incorrect++;
cout <<"You have chosen wrong answer. correct answer false." << endl;
}
cout <<"Total number of correct answers are " << (5-incorrect) << endl;
cout <<"Total number of incorrect answers are " << (incorrect) << endl;
system("pause");
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote