# Lecture3_4 - Lecture 3 - Making Decisions ECE 3090 Software...

This preview shows pages 1–14. Sign up to view the full content.

ECE 3090 Software for Engineering Systems Dr. Ayanna Howard School of Electrical and Computer Engineering Georgia Institute of Technology Lecture 3 - Making Decisions

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

View Full Document
2 Adapted from “Brief Version of Starting Out with C++” Relational Operators Used to compare numbers to determine relative order Operators: Not equal to != Equal to ( Do not confuse with =) == Less than or equal to <= Greater than or equal to >= Less than < Greater than > Boolean expressions – true (1) or false (0) 12 > 5 is true 7 <= 5 is false if x is 10, then x == 10 is true , x != 8 is true , and x == 8 is false
3 Adapted from “Brief Version of Starting Out with C++” The if Statement Allows statements to be conditionally executed or skipped over Models the way we mentally evaluate situations: "If it is raining, take an umbrella." "If it is cold outside, wear a coat."

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

View Full Document
4 Adapted from “Brief Version of Starting Out with C++” The if Statement General Format: if ( expression ) statement ; To evaluate: if ( expression ) statement ; If the expression is true , then statement is executed. If the expression is false , then statement is skipped.
5 Adapted from “Brief Version of Starting Out with C++”

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

View Full Document
6 Adapted from “Brief Version of Starting Out with C++” Expanding the if Statement To execute more than one statement as part of an if statement, enclose them in { } : if (score > 90) { grade = 'A'; cout << "Good Job!\n"; } { } creates a block of code
7 Adapted from “Brief Version of Starting Out with C++” The if/else Statement Provides two possible paths of execution Performs one statement or block if the expression is true, otherwise performs another statement or block. General Format: if ( expression ) statement1 ; // or block else statement2 ; // or block

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

View Full Document
8 Adapted from “Brief Version of Starting Out with C++” if/else – what happens To evaluate: if ( expression ) statement1 ; else statement2 ; If expression is true , then statement1 executed If expression is false , then statement2 is executed.
9 Adapted from “Brief Version of Starting Out with C++”

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

View Full Document
10 Adapted from “Brief Version of Starting Out with C++” The if/else if Statement Chain of if statements that test in order until one is found to be true Also models thought processes: “If it is raining, take an umbrella, else, if it is windy, take a hat, else, take sunglasses” if ( expression ) statement 1 ; // or block else if ( expression ) statement 2 ; // or block . . // other else ifs . else if ( expression ) statement n ; // or block
11 Adapted from “Brief Version of Starting Out with C++”

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

View Full Document
12 Adapted from “Brief Version of Starting Out with C++” Using a Trailing else Used with if/else if statement when none of the expressions are true Provides default statement/action Used to catch invalid values, other exceptional situations

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 06/09/2009 for the course ECE 3090 taught by Professor Staff during the Fall '08 term at Georgia Institute of Technology.

### Page1 / 60

Lecture3_4 - Lecture 3 - Making Decisions ECE 3090 Software...

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

View Full Document
Ask a homework question - tutors are online