Introduction: Multiway Decisions

Here are the prerequisites, learning objectives, and overview for this chapter.

We'll cover the following

Prerequisites

Objectives

After completing this chapter, you should be able to:

  • Write nested if statements
  • Use multiway if statements to cause one of several possible actions
  • Use a switch statement to cause one of several possible actions

Overview

Imagine that you are an intern with a local health club. New members can stop at a kiosk and interact with a program that you are to write. The program will give some advice about appropriate facilities according to the person’s age. Before the end of this chapter, you will be able to write this program.

The chapter, Decisions, introduced the basic if statement, with and without an else clause. This statement enables our programs to choose between two options. Many times, however, we are faced with more than two choices, just as we will be when writing the program for the health club. This chapter discusses how to deal with these situations by nesting several if statements or by using a new statement, the switch statement. A switch statement chooses from among several possible actions according to the value of an expression whose data type is either int, char, or enumerated.

Get hands-on with 1400+ tech skills courses.