Warning: The magic method Slickr_Flickr_Plugin::__wakeup() must have public visibility in /home/kenbauer/public_kenscourses/tc101fall2015/wp-content/plugins/slickr-flickr/classes/class-plugin.php on line 152
‘#Switch’ Articles at TC101 Fall 2015
Introduction to Programming Python and C++

Tag Archives: #Switch

Mastery 17

On this mastery I’ll show you what and how to use the conditional switch in C++.

Switch is a statement that tests a variable for equality in a list of given conditions. It is somehow a summarized version of IF when you have a lot of conditions. 

This flow chart may help you understand better, and this webpage too:

The default syntax of switch goes like this:

switch (expression)
case “condition” : outcome
[default:statement]    //This is used when the variable input isn’t a valid option.

So, for the purpose of this mastery, lets create a program were the user can input his points on masteries so far and tell him if his good or screwed. Do as follows:

  1. Create our “basic” program.
  2. Inside the int, declare a char variable with an assigned value.
  3. Use switch to condition the outcome and tell the user if his good or screwed.

Your program should look something like this:

Now let’s test it:

Let’s just play with another value:

Great! Now you know what and how to use switch conditional.

What should you work on?

Week #12 and more partial exams for you.

For this week's readings:
C++ (TC1017) should either be looking at support for your project, ImageMagick C++ libraries are a good start.
Python (TC1014) should be finishing chapter 11 (Dictionaries).