CECS 478 Lecture 6: Decisions and Conditions

27 views2 pages

Document Summary

Ex: buildings often skip the 13th floor and the elevators should too. 13th floor press 14 nth floor press n + 1: program will return the correct floor. Case one: n 12 : actual floor = floor. Case two: n > 12 : actual floor = floor 1: code: int actualfloor; int floor; (user input) if (floor 12) (in parenthesis called condition) actualfloor = floor; else actualfloor = floor 1. If (condition) statements; else no conditions here statements; Ex: floor < actualfloor + 1: actualfloor + 1 will be added first then compare. Problem with = = : ex: double r = 2. 0. Double d = math. sqrt(2); r == d * d will be considered false: to fix: if ( r == d * d) It"s correct : or double epsilon = 1e 14; if (math. abs(r d*d) < epsilon) True when: str1 = rob ; str2 = rob ;

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents