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...
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)....
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");...
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:...
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...
Write a C++ program that asks the user to enter the monthly costs for the following...
Write a C++ program that asks the user to enter the monthly costs for the following expenses incurred from operating your automobile: loan payment, insurance, gas, oil, tires, and maintenance. The program should then display the total monthly cost of these expenses, and a projected total annual cost of these expenses. Label each cost. The labels should be left aligned and have a column width of 30 characters. The cost should be aligned right and displayed with two decimal places...
Write a C program that loops and asks a user to enter a an alphanumeric phone...
Write a C program that loops and asks a user to enter a an alphanumeric phone number and converts it to a numeric one. No +1 at the beginning. You can put all code in one quiz1.c file or put all functions except main in phone.c and phone.h and include it in quiz1.c Submit your *.c and .h files or zipped project */ #pragma warning (disable: 4996) //windows #include <stdio.h> #include <string.h> #include <stdbool.h> #include <ctype.h> enum { MaxLine =...
Write a c++ program that asks the user for a date (Month and Day only) and...
Write a c++ program that asks the user for a date (Month and Day only) and displays the season in this day.The program asks then the user if he needs to enter another date, if he answers with ’Y’ or ’y’, the programwill take another date from the user and displays the season in this day.The program will keep repeating this until the user enters a character different than ’Y’ and ’y’.•Fall starts in September 21st•Winter starts in December 21st•Spring...
C++ write a program that asks the user to enter the hours and rate then calculate...
C++ write a program that asks the user to enter the hours and rate then calculate the gross pay for an employee, the program should test if the hours are regular (40), any hour more than 40 should be paid with the overtime rate: 1.5*rate. The program should ask repeatedly the user if he/she wants to continue: y or n, if the user types y, then the program should ask for the hours and rate for another employee then display...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT