L05_selection-1 - Making Decisions Making Decisions...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Making Decisions Making Decisions Relational and Logical Operators and Expressions Control Structures if and if-else statements EECS 183: University of Michigan Lecture 05 Mary Lou Dorf Nested if Where we are Headed Where we are Headed decision making decision making int minimum(int x, int y) { int min; if ( x > y ) { min = y; x > y true false EECS 183: University of Michigan Lecture 05 Mary Lou Dorf } else { min = x; } return min; } min = y; min = x; return min A Note about A Note about true true and and false false use bool type for variables with values true or false EECS 183: University of Michigan Lecture 05 Mary Lou Dorf in C++, when expressions are evaluated, zero value is considered false, any non-zero value is considered true Relational & Logical Operators Relational & Logical Operators Relational Operators < <= > >= == != Logical Operators EECS 183: University of Michigan Lecture 05 Mary Lou Dorf && ( and ) || ( or ) ! ( not ) used to compare values Relational Operators Relational Operators all are binary two operands x > y is x greater than y? x < y is x less than y? x >= y is x greater than or equal to y? x <= y is x less than or equal to y? == y x equal to y? EECS 183: University of Michigan Lecture 05 Mary Lou Dorf x == y is x equal to y? x != y is x not equal to y? all evaluate to either true or false assume assume x is 10 and y is 7 x is 10 and y is 7 x < y x > y x >= y EECS 183: University of Michigan Lecture 05 Mary Lou Dorf x <= y y != x bool undergrad = true; int age = 20; char gender = 'F'; EXPR___ ndergrad Example Relational Expressions Example Relational Expressions VALUE ue EECS 183: University of Michigan Lecture 05 Mary Lou Dorf undergrad age <= 25 gender == 'M' gender = 'M' (age % 2) == 0 true true false true ('M') (Also: gender M) true OPERATOR ASSOCIATIVITY HIGH ( ) left to right ! + - cast unary; right to left * / % left to right Precedence Rules Precedence Rules Recap Recap EECS 183: University of Michigan Lecture 05 Mary Lou Dorf + - left to right < <= > >= left to right == != left to right = right to left LOW swap out for swap out for L05_example 1.cpp L05_example 1.cpp EECS 183: University of Michigan Lecture 05 Mary Lou Dorf solve solve 1) given x = 5, y = 6, z = 8 what is the value of x == 5 (2 + x) != y Is the following correct? EECS 183: University of Michigan Lecture 05 Mary Lou Dorf x <= y is the same as y > x If it is true that x > y and it is also true that x < z, does that mean y < z is true? SEQUENCE SEQUENCE tatement tatement tatement . . . EECS 183: University of Michigan Lecture 05 Mary Lou Dorf Statement Statement Statement SELECTION(branch) SELECTION(branch) IF Condition THEN Statement1 ELSE Statement2 EECS 183: University of Michigan Lecture 05 Mary Lou Dorf Statement1 Statement Statement2 Condition . . . if statement ("if if statement ("if-then")...
View Full Document

Page1 / 49

L05_selection-1 - Making Decisions Making Decisions...

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

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