Reference no: EM132217497
Writing a Simple C++ Program switch statements are commonly, and easily, compared to if-else statements.
They both hold similar tree branching logic, but their syntax and usability are different. switch statements are powerful when you are considering one variable, especially when there are several different outcomes for that variable.
It is important to understand that a break statement should be used for each case that requires a different outcome, or the code may "leak" into the other cases.
However, be sure to note that the outcome for different cases may be shared by omitting the break. Write a complete C++ program called Lab5B. opt that uses a switch statement to print out the network affiliations for a few network channels based on the integer that the user enters for a channel up to and including channel 13. In our lab program, channel 4 is FOX, channel 5 is NBC, channel 8 is ABC, channel 11 is CBS, and channel 13 is PBS.
If a user enters one of these values, you are to print out the channel number along with its network affiliation. If a user enters a channel outside of these, you will output a meaningful error message that the channel the user input is not available. You must solve this using a switch statement.
Before writing the code, you may want to write out the algorithm, or steps, on paper of how you propose to solve this problem. Feel free to reference the class lecture notes to see how you might accomplish this.