Hello Computer Science: C++ Switch

Prepare today for the demands of tomorrow.

Hello C++: Switch/Case

At the end of this lesson you will know what a switch expression is and how to use them in a program. You will be able to write a program that will use switch expressions to determine the sequence of actions.

1. Print and read the lesson. (Punch, staple, put in your binder.)
Switch, if, else

2. Run each of the programs from the lesson:

Tip based on service
Season1
: with switch
Season2: with if
Season3: with if and || (or) Flowchart
Season4: with nested if/else
Season5: both && and ||
Pay1

To get the most out of these programs

3. Using the sample programs as a model, write a program that will ask the cost of a meal and then ask the user to rank the service. Print out how much tip to leave. 10% for poor service, 15% for average service, 20% for good service.

Follow good programming habits:

Summary: The switch statement provides an alternative to using a nested if/else block. It is a good choice when a variable has a limited number of possible values.

The general format for a switch block is:

All of the computer_science activities with description in Arabic, 汉语, English, Français, Deutsch, Indonesian, Italiano, 日本語, Portuguêes, Русский, Español,


Copyright © Hello World Publications. All rights reserved worldwide.

hello-world.com
Privacy
Policy

Site map

Hello-World