Question

In: Computer Science

With C code Write a switch statement (not a complete program) which prints an appropriate message...

With C code

Write a switch statement (not a complete program) which prints an appropriate message for a letter code entered. Use the following messages:

If L is entered, output the message "Lakers"

If C is entered, output the message "Clippers"

If W is entered, output the message "Warriors"

If any other character is entered, output the message "invalid code"

Make sure to handle the case where the user enters in a small letter.

That is, a capital or small l should output the message “Lakers”.

printf("enter a letter code");

scanf("%c", &code);

Solutions

Expert Solution

switch(tolower(code)){
            case 'l':
                printf("Lakers");
                break;
           case 'c':
                printf("Clippers");
                break;
           case 'w':
                printf("Warriors");
                break;
           default:
                printf("invalid code");
                break;
        }

NOTE: The above code snippet is in C language. Please refer to the attached screenshots for code indentation and sample I/O.

Complete Code For Reference:

Sample I/O:


Related Solutions

Question: Write a complete C++ program that runs multiple tests and calculations using switch statement. Based...
Question: Write a complete C++ program that runs multiple tests and calculations using switch statement. Based on your input and the selection from the keyboard, the program does the followings. If the selection is 1, the program should test the input if it’s positive, negative or zero. For example, the output should be “The selection is 1 to test the input value if it’s positive, negative or equal to zero. The input value 7 is positive” If the selection is...
write a C program which performs encryption and decryption of a message
write a C program which performs encryption and decryption of a message
Why won't the program run the code after the first switch statement. It shows Press c...
Why won't the program run the code after the first switch statement. It shows Press c to continue or q to quit, but does not give the user the option to fill it in. Please help to run the code fully. This program is to find the area of shapes the user decides and must give them an option to quit or restart the program. Please provide the explanation and code in JAVA here. Thank you. import java.util.Scanner; import java.lang.Math;...
Your task is to write a C program which performs encryption and decryption of a message...
Your task is to write a C program which performs encryption and decryption of a message using the substitution cipher algorithm. Write a C program which performs encryption and decryption using the substitution cipher algorithm. Your program must be fully automated (ie: it does not take any interactive user input) and either encrypt or decrypt depending on the files which exist in the program’s directory. If message.txt exists your program should read that file, encrypt the contents, and write the...
Using c# , Write a program using a switch statement that takes one character value from...
Using c# , Write a program using a switch statement that takes one character value from the user and checks whether the entered value is an arithmetic operator (+, -, * , /) If not the program display a message that it not of the operators ( (+, -, * , /) .
No Global variables No goto statement No break outside switch Write a menu driven C program...
No Global variables No goto statement No break outside switch Write a menu driven C program using functions and switch. Feel free to use “Empty Outlines” template from Canvas to design the functions as needed to build the code. Make sure to submit your work through Canvas. You can show me your code running in class when you are done. The program shows following menu to the user repetitively until user selects option 3 to exit. Circle Triangle Exit Based...
Write a C program which prints the environment variables to a file "sample.txt" . All variables...
Write a C program which prints the environment variables to a file "sample.txt" . All variables are followed by a newline character. example: example: inputs: envp/environ = {"E1=5","E2=9",NULL} outputs: env.txt as a string would be "E1=5\nE2=9\n".
Programming in C++ Write a program that prints the values in an array and the addresses...
Programming in C++ Write a program that prints the values in an array and the addresses of the array’s elements using four different techniques, as follows: Array index notation using array name Pointer/offset notation using array name Array index notation using a pointer Pointer/offset notation using a pointer Learning Objectives In this assignment, you will: Use functions with array and pointer arguments Use indexing and offset notations to access arrays Requirements Your code must use these eight functions, using these...
Write a C++ program which prints consecutive dates to the console window starting at January 1,...
Write a C++ program which prints consecutive dates to the console window starting at January 1, 2000, as follows. Saturday, January 1, 2000 Sunday, January 2, 2000 Monday, January 3, 2000 Tuesday, January 4, 2000 ... You will define a function which prints the dates indefinitely, exactly as given above, or prints a specific number of dates. For example, if your function prints 7,581 days the result would look like this. Saturday, January 1, 2000 Sunday, January 2, 2000 ......
Write a C program, char.c, which prints the numerical value of the special character constants given...
Write a C program, char.c, which prints the numerical value of the special character constants given below. Don’t just look up the codes and print them directly from your program. You should have your program output the values of the character constants by using them as string literals within your printf() statements. Your output should be presented in a neat, orderly, tabular format as shown below: Char Constant Description Value '\n' newline '\t' horizontal tab '\v' vertical tab '\b' backspace...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT