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

Need to write a c program Program prints a message telling the user to push a...
Need to write a c program Program prints a message telling the user to push a key to start the game. Once in game, output tells the player which key to push. The key to press should be determined randomly. Game runs continuously until the user reaches a loose condition. A wrong key is pressed
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".
Have a look at the code below. Write a switch statement to check for the mode...
Have a look at the code below. Write a switch statement to check for the mode type. When the designated mode is matched, display an appropriate string for that mode. The default case should display the statement, “We do not offer this mode of course delivery.” public class SwitchCourse {     enum CourseMode { ONLINE, RESIDENTIAL, HYBRID }     CourseMode myCourse = CourseMode.HYBRID;        public void myCourse()     {         switch (/*___*/)         {             case ONLINE:                 System.out.println("You...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT