Question

In: Computer Science

. 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 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.

Solutions

Expert Solution

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;

}


Related Solutions

Question : Write a C program that asks the user to enter an integer between 1...
Question : Write a C program that asks the user to enter an integer between 1 and 7 that represents a weekday number (1 = Sunday, 2 = Monday , …… , 6 = Friday , 7 = Saturday) and it prints the day (i.e., Sunday, Monday, …… , Friday or Saturday). The program continuously asks the user to enter a weekday number till the user responds by ‘N’. and give me an output please use printf and scanf #include...
Write a C ++ program that asks the user for the speed of a vehicle (in...
Write a C ++ program that asks the user for the speed of a vehicle (in miles per hour) and how many hours it has traveled. The program should then use a loop to display the distance the vehicle has traveled for each hour of that time period. Here is an example of the output: What is the speed of the vehicle in mph? 40 How many hours has it traveled? 3 Hour Distance Traveled -------------------------------- 1           40 2           80...
Question Write a C program that asks the user to enter two integers x and n....
Question Write a C program that asks the user to enter two integers x and n. Then the program computes xn (=x * x * x …… (n times)) using for loop. and give me an output please use printf and scanf #include int main(void) {     //Declare required variables             //read two integers x , n from the keyboard                 //compute xn using for loop                     printf("< Your name >\n");...
Tail of a File, C++ Program. write a program that asks the user for the name...
Tail of a File, C++ Program. write a program that asks the user for the name of a text file. The program should display the last 10 lines, or all lines if less than 10. The program should do this using seekg Here is what I have so far. #include<iostream> #include<fstream> #include<string> using namespace std; class File { private:    fstream file;    string name; public:    int countlines();    void printlines(); }; int File::countlines() {    int total =...
Program specifics: Write a C++ program that does the following: a. Asks the user for the...
Program specifics: Write a C++ program that does the following: a. Asks the user for the distance to the pin and the depth of the green (both in yards). (Note: The pin is the hole in the green and the depth is the diameter of the green, assuming it is circular.) b. Asks the user for an integer club number from 2 to 10, where 10 is the pitching wedge (this club lifts the ball out of rough, sand, etc)....
Write a c++ program that asks the user to choose his preferred shape, and asks then...
Write a c++ program that asks the user to choose his preferred shape, and asks then for two numbers (positive but not necessary integers) in order to calculate the shape's area. The possible shapes are: Triangle, Ring and Rectangle. If the user chose a different shape, you will warn him and wait for a valid shape. The area of a circle is πr12-r22 (suppose π= 3.4 ). The area of a triangle is base*height/2. The area of a rectangle is...
In C write a program that asks the user for the dimensions of 3 sides of...
In C write a program that asks the user for the dimensions of 3 sides of a triangle. Each side dimension must be between 1.00 and 100.00 including 1.00 and 100.00. If the side dimensions indeed can make a valid triangle then the program should use these values to determine the perimeter and the area of the valid triangle 1. Must use programmer define functions 2. Your program must have at least 4 functions, main and the following 3 functions:...
c program Write a program that asks the user to enter a sequence of 15 integers,...
c program Write a program that asks the user to enter a sequence of 15 integers, each either being 0, 1, or 2, and then prints the number of times the user has entered a "2" immediately following a "1". Arrays are not allowed to appear in your code. Include ONLY THE SCREENSHOT OF YOUR CODE in an image file and submit the file.
A multiple -choice test question has four possible responses. The question is designed to be very...
A multiple -choice test question has four possible responses. The question is designed to be very difficult, with none of the four responses being obviously wrong, yet with only one correct answer. It first occurs on an exam taken by 400 stude nts. The designers test whether more people answer the question correctly than would be expected just due to chance (i.e., if everyone randomly guessed the correct answer). a) Set up the hypotheses for the test. b) Of the...
2. Write a program C++ that asks the user for a number (not necessary to force...
2. Write a program C++ that asks the user for a number (not necessary to force any particular requirements). Write a function with the following signature: double square(double x) that returns the square of the user's number (x * x). 3. Write a C++ program that asks the user for an integer. Write a function that returns 1 of the number is even, and 0 if the number is odd. Use this function signature: int isEven(int x). 4. Write a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT