Programming in C++Dale/Weems/HeadingtonChapter 5 ContinuedSelection 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
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?
Both the if clause and the else clause
Multi-alternative selection
NESTED if statements
Multi-way branching
Writing NESTED if statements
One answer
Other answer
Write a void function
Using selection
Bad Example has output: FAIL
To correct the problem, use braces
Email: ssorkin@essex.cc.md.us
Home Page: http://www.essex.cc.md.us/Essex/People/ssorkin/index.html
Download presentation source