Question

show how you would create a switch statement to evaluate an integer corresponding to a month...

show how you would create a switch statement to evaluate an integer corresponding to a month of the year(1 through 12) and the output to the command window the appropriate statement. if the number in the controlling expression is a 1,2,11 or 12, output"its cold out there". if the nukber is 3,4,9 or 10, output" its mild out here" finally if the number is a 5,6,7 or 8, output" its nice and warm" to the command window. make sure you code an efficient switch -case based on unique capabilities of a switch.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE:

#include <stdio.h>
int main()
{
int month;
printf("Enter month\n");
scanf("%d",&month);
switch(month)
{
case 1: case 2:case 11:case 12: printf("its cold out there\n");
break;
case 3: case 4:case 9:case 10: printf("its mild out there\n");
break;
case 5: case 6:case 7:case 8: printf("its nice and warm\n");
break;

default : printf("invalid choice");
break;
}
  
return 0;
}

NOTE: HERE WE ARE USING MULTIPLE CASE VALUE WITH HAVING ONLY SINGLE BODY TO MAKE OUR CODE EFFICIENT.


Add a comment
Know the answer?
Add Answer to:
show how you would create a switch statement to evaluate an integer corresponding to a month...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Pick a switch statement from the reading. Put it into a main() Java program and make...

    Pick a switch statement from the reading. Put it into a main() Java program and make it work. Attach the .java file and copyAndPaste the output into the WriteSubmissionBox The switch Statement S1.51 Multiway if-else statements can become unwieldy when you must choose from among many possible courses of action. If the choice is based on the value of an integer or character expres- sion, the switch statement can make your code easier to read. The switch statement begins with...

  • 8. Exercise 5.6 Switch Statements Objective: Create a switch statement that accepts an integer input from...

    8. Exercise 5.6 Switch Statements Objective: Create a switch statement that accepts an integer input from 1 to 12 and returns a String of the related month name. For any other number, return Invalid Number. Steps: Create a file named Ex_5_6.java and appropriate class name and main() method. Create a method using the following signature: pubilc static String monthNumberToString(int monthNumber) In the main() method, add in the following code: System.out.println(monthNumberToString(1)); This will allow you to test your code. Modify the...

  • Project 4-3: In the following steps, you will learn more about the PING (Packet Internet Grouper)...

    Project 4-3: In the following steps, you will learn more about the PING (Packet Internet Grouper) utility, which can be used on a network running IPv4 to verify that TCP/IP is configured correctly and communicating with the network. A ping test is typically the first thing network professionals try when troubleshooting a TCP/IP connection problem. For this project, you can use any type of workstation that's running TCP/IPv4, preferably one connected to the Internet. The output described in the following...

  • Having trouble with the do while/while loop and the switch statement. I got some of the...

    Having trouble with the do while/while loop and the switch statement. I got some of the switch statement but cant get the program to repeat itself like it should.What i have so far for my code is below. Any help is appreciated... i am not sure what I am doing wrong or what i am missing. I am completely lost on the while loop and where and how to use it in this scenario. import java.util.Scanner; public class sampleforchegg {...

  • QUESTION 7 Which of the following is a valid C++ assignment statement? (assume each letter is...

    QUESTION 7 Which of the following is a valid C++ assignment statement? (assume each letter is a different variable) A.y=b-c B.y +z = x C.x = a bi D.x = -(y*z): Ex = (x + (y z): QUESTION 8 Which of the following is a valid variable name according to C++ naming rules? A 2ndName B.%Last_Name C@Month D#55 Eyear03 QUESTION 9 Which library must be included to enable keyboard input? A kbdin B. cstdlib C input Diostream E lomanip QUESTION...

  • How do i write the pseudocode for this java code? First, write out pseudocode, and then create a program to help you by accomplishing the following tasks: :  Use command line interface to ask the use...

    How do i write the pseudocode for this java code? First, write out pseudocode, and then create a program to help you by accomplishing the following tasks: :  Use command line interface to ask the user to input the following. ○ How many apples are on hand ○ How many apples should be in stock ○ How many oranges are on hand ○ How many oranges should be in stock  Perform an operation to determine how many of...

  • Infix Expression Evaluator For this project, write a C program that will evaluate an infix expression. The algorithm REQ...

    Infix Expression Evaluator For this project, write a C program that will evaluate an infix expression. The algorithm REQUIRED for this program will use two stacks, an operator stack and a value stack. Both stacks MUST be implemented using a linked list. For this program, you are to write functions for the linked list stacks with the following names: int isEmpty (stack); void push (stack, data); data top (stack); void pop (stack); // return TRUE if the stack has no...

  • Infix Expression Evaluator For this project, write a C program that will evaluate an infix expression. The algorithm REQ...

    Infix Expression Evaluator For this project, write a C program that will evaluate an infix expression. The algorithm REQUIRED for this program will use two stacks, an operator stack and a value stack. Both stacks MUST be implemented using a linked list. For this program, you are to write functions for the linked list stacks with the following names: int isEmpty (stack); void push (stack, data); data top (stack); void pop (stack); // return TRUE if the stack has no...

  • Any little bit of information will be helpful. Thank you. Problem Statement You are to develop a program to read Mo...

    Any little bit of information will be helpful. Thank you. Problem Statement You are to develop a program to read MotoGP rider information from an input file. You will need a MotoGpRider class whose instances will be used to store the statistics for a MotoGP motorcycle racer. The Rider class will have attributes for last name, first name, racing number, nation, motorcycle make, world championship points, world championship position, and an array that stores the number of top finishes (number...

  • Your goal is to create an ‘Array’ class that is able to hold multiple integer values....

    Your goal is to create an ‘Array’ class that is able to hold multiple integer values. The ‘Array’ class will be given functionality through the use of various overloaded operators You will be given the main() function for your program and must add code in order to achieve the desired result. Do not change any code in main(). If something is not working, you must change your own code, not the code in main(). Assignment 5: overloading member functions. Overview:...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT