In: Computer Science
. 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 that the
input is incorrect.
The below example shows three runs of the program, one for each
type of response (correct, incorrect, invalid input). You are
welcome to change the quiz question and answers, but there must be
a single correct answer to your quiz question.
Tip: use "\t" in your printf statements to print a tab and get
indented output like the quiz answers in the output below.
Welcome to the Quizzer! Here's your question...
What is the name of Mat's cat? (a) Fluffy (b) Kitty Purry (c)
Munster (d) Crookshanks
Your answer: c Correct!
Welcome to the Quizzer! Here's your question...
What is the name of Mat's cat? (a) Fluffy (b) Kitty Purry (c)
Munster (d) Crookshanks
Your answer: b Wrong!
Welcome to the Quizzer! Here's your question...
What is the name of Mat's cat? (a) Fluffy (b) Kitty Purry (c)
Munster (d) Crookshanks
Your answer: x Invalid input.
If you have any doubts, please give me comment...
#include<stdio.h>
int main(){
char answer;
printf("Welcome to the Quizzer! Here's your question...");
printf("\n\nWhat is the name of Mat's cat?");
printf("\n(a) Fluffy\t(b) Kitty Purryt\t(c) Munster\t(d) Crookshanks");
printf("\nYour answer: ");
scanf("%c", &answer);
if(answer!='a' && answer!='b' && answer!='c' && answer!='d')
printf("Invalid input\n");
else if(answer=='c')
printf("Correct!\n");
else
printf("Wrong!\n");
return 0;
}