Selection in C++

Selection in C++ - SelectioninC+ If statements...

Info iconThis preview shows pages 1–11. Sign up to view the full content.

View Full Document Right Arrow Icon
Selection in C++ If statements
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Control Structures Sequence Selection Repetition Module
Background image of page 2
Selection If or if / else statement choosing between mutually exclusive possibilities Two forms if (logical expression) statement; if (logical expression) statement; else statement;
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Logical Expressions Relational Operators ==, !=, <=, >=, >, < They are binary operators – have two operands work on any type of data, be careful about matching types watch out for = and == produce a bool result
Background image of page 4
Syntax of if statement if (logical expression) statement; Don't put semicolon after condition Indentation helps humans, doesn't matter to compiler
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Syntax of if statement if (x > 0) y = sqrt(x); if (x > y) t = x; x = y; y = t; // what goes with the if?
Background image of page 6
If-Then Statement Determine whether or not to execute a statement (which can be a  single statement or an entire block) TRUE FALSE statement expression
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Examples output larger of two numbers don't allow sqrt of negative number don't allow overflow determining even or odd give student another chance at a question
Background image of page 8
Visual Aid Decision tree “if person is 18 or over and state is KY, they can have regular license” “if person is 16 or over and under 18 and state is TN or VA, they can have learner’s permit” “if person is under 16, in any state, they can’t have license” “if person is over 65 in VA, they have modified license”
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
What is output? Why? int
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/13/2011 for the course CS 115 taught by Professor Staff during the Fall '08 term at Kentucky.

Page1 / 33

Selection in C++ - SelectioninC+ If statements...

This preview shows document pages 1 - 11. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online