Question

In: Computer Science

In C++ Language: Program a multiple(4) choice quiz with 10 question that allows the user to...

In C++ Language: Program a multiple(4) choice quiz with 10 question that allows the user to input their choice. Validate their choice, if choice is valid continue. If choice is not valid have the user input a different answer. If the user gets 3 of the 10 choices incorrect, then the quiz is over.

Solutions

Expert Solution

Note: Based on the requirement i developed a code that no of incorrect answers count is <=3

Could you plz go through this code and let me know if u need any changes in this.Thank You
_________________

#include <fstream>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdlib>
using namespace std;

//Declaring the function
char getValidChoice();
int main() {
   //Declaring constant
   const int SIZE=10;
   //Declaring variables
int correct=0,inCorrect=0;
  
//Declaring and initializing an array
   char ans[]={'A','B','A','D','D','A','C','D','A','D'};
   char userAns[SIZE];
  
   //This loop will continue until the user incorrect answers count is <=3
   while(true)
   {
   for(int i=0;i<SIZE;i++)
   {
       cout<<"Question#"<<(i+1)<<":"<<endl;
       userAns[i]=getValidChoice();
   }
  
   for(int i=0;i<SIZE;i++)
   {
   if(userAns[i]==ans[i])  
   {
       correct++;
   }
   else
   {
       inCorrect++;
   }
   }
  
   if(inCorrect<=3)
   {
       cout<<"** Quiz is over **"<<endl;
       cout<<"No of Correct :"<<correct<<endl;
       cout<<"No of Incorrect :"<<inCorrect<<endl;
       break;
   }
   else
   {
   system ("CLS");
   }      
   }

  
  
   return 0;
}
char getValidChoice()
{
   char choice;
   while(true)
   {
       cout<<"Enter Answer :";
       cin>>choice;
       choice=toupper(choice);
       if(choice!='A' && choice!='B' && choice!='C' && choice!='D')
       {
           cout<<"** Inavlid Choice.Must be either A , B , C or D **"<<endl;
       }
       else
       break;
   }
   return choice;
}

______________________________

Output:

____________________Thank Youi

C:\Program Files (x86)\Dev-Cpp\MinGW64\bin\Quiz 10Questions.exe Question#1: Enter Answer :A Question#2: Enter Answer :F ** Inavlid Choice. Must be either A, B, C or D ** Enter Answer :B Question#3: Enter Answer :A Question#4: Enter Answer :D Question#5: Enter Answer :D Question#6: Enter Answer :A Question#7: Enter Answer :C Question#8: Enter Answer :D Question#9: Enter Answer :D Question#10: Enter Answer :C ** Quiz is over ** No of Correct :8 No of Incorrect :2 Process exited after 18.46 seconds with return value o Press any key to continue ....


Related Solutions

. Write a C program that asks the user a multiple-choice question and shows four possible...
. Write a C program that asks the user a multiple-choice question and shows four possible answers, (a) through (d). Prompt the user to input a response as a character. If the user enters the correct response, print a message stating that the answer is correct. If the user enters an incorrect response, print a message stating that the answer is wrong. If the user enters anything other than the letters a, b, c, or d, print a message stating...
A pop quiz has two questions. Question 1 is a multiple choice question with 4 possible...
A pop quiz has two questions. Question 1 is a multiple choice question with 4 possible answers. Question 2 is a true/false question. One student is completely unprepared for the quiz and has to guess the answers. Let X denote the number of questions answered correctly. 1. List all possible results for the student's quiz and their probabilities. Use C to denote a correct answer and I to denote and incorrect answer. 2. List the possible values for X. 3....
Create a basic program (C programming language) that accomplishes the following requirements: Allows the user to...
Create a basic program (C programming language) that accomplishes the following requirements: Allows the user to input 2 numbers, a starting number x and ending number y Implements a while loop that counts from x (start) to y(end). Inside the loop, print to the screen the current number Print rather the current number is even or odd If the number is even , multiply by the number by 3 and print the results to the screen. If the number is...
Isabel is taking a multiple-choice question quiz. The quiz has 7 questions and each question has...
Isabel is taking a multiple-choice question quiz. The quiz has 7 questions and each question has 4 possible answers (only one of them is a correct answer). Since she didn’t study at all, she will guess all the questions. Let X be the random variable representing the number of answers she’ll guess correctly. (3 pts) What values does X take on? (4 pts) Calculate the probability that she guesses 2 questions correctly. (4 pts) Calculate the probability of passing the...
Questions 3-4: You are guessing at random on an 11-question multiple choice quiz. Each question has...
Questions 3-4: You are guessing at random on an 11-question multiple choice quiz. Each question has five choices, one of which is correct. 3. What is the probability of getting 5 or more questions correct?: * (A) 0.0117 (B) 0.0504 (C) 0.9496 (D) 0.9883 4. How many questions do you expect to get correct?: * (A) 2.2 (B) 4.8 (C) 5 (D) 5.5 5. A 95% confidence interval for the proportion of people who believe the Loch Ness Monster exists...
Please code C# 10. Write a program that allows a user to input names and corresponding...
Please code C# 10. Write a program that allows a user to input names and corresponding heights (assumed to be in inches). The user can enter an indefinite number of names and heights. After each entry, prompt the user whether they want to continue. If the user enters true, ask for the next name and height. If the user enters false, display the name of the tallest individual and their height. Sample run: “Name?” James “Height?” 50 “Continue?” True “Name?”...
Richard has just been given a 4-question multiple-choice quiz in his history class. Each question has...
Richard has just been given a 4-question multiple-choice quiz in his history class. Each question has five answers, of which only one is correct. Since Richard has not attended class recently, he doesn't know any of the answers. Assuming that Richard guesses on all four questions, find the indicated probabilities. (Round your answers to three decimal places.) (a) What is the probability that he will answer all questions correctly? (b) What is the probability that he will answer all questions...
Richard has just been given a 4-question multiple-choice quiz in his history class. Each question has...
Richard has just been given a 4-question multiple-choice quiz in his history class. Each question has five answers, of which only one is correct. Since Richard has not attended class recently, he doesn't know any of the answers. Assuming that Richard guesses on all four questions, find the indicated probabilities. (Round your answers to three decimal places.) (a) What is the probability that he will answer all questions correctly? (b) What is the probability that he will answer all questions...
Richard has just been given a 10-question multiple-choice quiz in his history class. Each question has...
Richard has just been given a 10-question multiple-choice quiz in his history class. Each question has four answers, of which only one is correct. Since Richard has not attended class recently, he doesn't know any of the answers. Assuming that Richard guesses on all ten questions, find the indicated probabilities. (Round your answers to three decimal places.) (a) What is the probability that he will answer all questions correctly? (b) What is the probability that he will answer all questions...
Program must be in C Write a program that allows the user to enter the last...
Program must be in C Write a program that allows the user to enter the last names of five candidates in a local election and the number of votes received by each candidate in two different arrays. The program should then output each candidate’s name, the number of votes received, and the percentage of the total votes received by the candidate. Your program should also output the winner of the election. Example (Letters and numbers with underscore indicate an input):...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT