Question: I need help on this C code. Please be clear. Purpose: Steps: What is the same and what is different about if statements and switch

I need help on this C code. Please be clear.

Purpose:

Steps:

What is the same and what is different about if statements and switch statements

Explain how you tested and verified all the possibilities of the program function correct

/*-------------------------------------------------------------------------------

HEADER FILES

NOTE: The processor specific header file is not required since we will not

be using any processor specific features - this is all generic C code

-------------------------------------------------------------------------------*/

#include // Processor specific header file

#include // Standard I/O - required for printf() function

/*-------------------------------------------------------------------------------

PROGRAM CONSTANTS

-------------------------------------------------------------------------------*/

#define CBS 4

#define NBC 5

#define ABC 7

/*-------------------------------------------------------------------------------

VARIABLE DECLARATIONS

-------------------------------------------------------------------------------*/

int channel = 1;

/*-------------------------------------------------------------------------------

FUNCTION PROTOTYPES

-------------------------------------------------------------------------------*/

int main(void);

/*===============================================================================

FUNCTION: main()

DESCRIPTION: Prints TV channels from 2 to 10 with their network affiliation

PARAMETERS: none

RETURNS: nothing

REQUIREMENTS: none

===============================================================================*/

int main(void)

{

/*---------------------------------------------------------------------------

Main Program Loop

---------------------------------------------------------------------------*/

while(channel < 10)

{

channel++; //Increment channel

/*###########################################################################

# TASK: Write a switch statement to print the network's initials with the

# channel (based on Chicago TV stations).

# * If channel = 2, print "CBS 2" to the output window.

# * If channel = 5, print "NBC 5" to the output window.

# * If channel = 7, print "ABC 7" to the output window.

# * For all other channels, print "--- #" to the output window,

# where "#" is the channel number.

# (HINT: Use printf(), and use the newline character ' ' at the end

# of each string you print to the output window.)

# NOTE: The switch statement is in a loop that will execute 9 times. Each

# pass through the loop, 'channel' will be incremented. The output

# window should display a line of text for channels 2 to 10.

#

# STEP 1: Open a switch statement on the variable 'channel'

###########################################################################*/

switch(channel) //### Begin switch statement

{

/*###########################################################################

# STEP 2: Write case for channel = CBS (CBS is a constant defined to equal 2)

###########################################################################*/

//### Your Code Here ### //### If channel = CBS (CBS = 2)

{

//### Your Code Here ### //### Display string "CBS 2" followed by newline

//### Your Code Here ### //### Prevent fall through to next case

}

/*###########################################################################

# STEP 3: Write case for channel = NBC (NBC is a constant defined to equal 5)

# This should look almost identical to step 2.

###########################################################################*/

//### Your Code Here ### //### If channel = NBC (NBC = 5)

{

//### Your Code Here ### //### Display string "NBC 5" followed by newline

//### Your Code Here ### //### Prevent fall through to next case

}

/*###########################################################################

# STEP 4: Write case for channel = ABC (ABC is a constant defined to equal 7)

# This should look almost identical to step 2.

###########################################################################*/

//### Your Code Here ### //### If channel = ABC (ABC = 7)

{

//### Your Code Here ### //### Display string "ABC 7" followed by newline

//### Your Code Here ### //### Prevent fall through to next case

}

/*###########################################################################

# STEP 5: Write default case. If channel is anything other than those

# listed above, this is what should be done. For these cases, you

# need to print the string "--- #" where "#" is the channel number.

# For example, if channel = 6, you should print "--- 6".

###########################################################################*/

//### Your Code Here ### //### For all other channels

{

//### Your Code Here ### //### Display string "--- #" followed by newline

}

}

}

while(1);

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!