Programming in C++ Dale/Weems/Headington Chapter 5 Continued Selection Control Structures

9/20/99


Click here to start


Table of Contents

Programming in C++ Dale/Weems/Headington Chapter 5 Continued Selection Control Structures

Flow of Control

Selection statements

CONTROL STRUCTURES

In C++

What can go wrong here?

Improved Version

if ... else SYNTAX

if ... else provides two-way selection

USE OF BLOCKS RECOMMENDED

PPT Slide

PPT Slide

Braces can only be omitted when each clause is a single statement

if...else for a mail order

These braces cannot be omitted

if statement is a selection

Terminating your program

These are equivalent. Why?

Each I/O stream has a state (condition)

How can you tell the state?

Checking on the state

Write if or if..else for each

Some Answers

Remaining Answer

What output? and Why?

What output? and Why?

What output? and Why?

What output? and Why?

Both the if clause and the else clause

Multi-alternative selection

NESTED if statements

NESTED if statements

Multi-way branching

Writing NESTED if statements

One answer

Other answer

Write a void function

PPT Slide

PPT Slide

Using selection

PPT Slide

PPT Slide

PPT Slide

Bad Example has output: FAIL

To correct the problem, use braces

Author: Sylvia Sorkin

Email: ssorkin@essex.cc.md.us

Home Page: http://www.essex.cc.md.us/Essex/People/ssorkin/index.html

Download presentation source