Making Logical Decisions (IF-THEN-ELSE)

Slides:



Advertisements
Similar presentations
Chapter 4 - Control Statements
Advertisements

CS&E 1111 ExIFs IFs and Nested IFs in Excel Objectives: Using the If function in spreadsheets Nesting If functions.
1.
Decisions (Conditional Programming) Chapter 5 (Sec. 5.1 & 5.2)
CS 1400 Chapter 4, sections Relational operators Less than< Greater than> Less than or equal= Equal== Not equal!=
CS 1400 Jan 2007 Chapter 4, sections Relational operators Less than< Greater than> Less than or equal= Equal== Not equal!=
259 Lecture 4 Spring 2010 Logical Functions and Conditional Formatting in Excel.
Spreadsheets Objective 6.02
2 Explain advanced spreadsheet concepts and functions Advanced Calculations 1 Sabbir Saleh_Lecture_17_Computer Application_BBA.
EGR 2261 Unit 4 Control Structures I: Selection  Read Malik, Chapter 4.  Homework #4 and Lab #4 due next week.  Quiz next week.
XOR and XNOR Logic Gates. XOR Function Output Y is TRUE if input A OR input B are TRUE Exclusively, else it is FALSE. Logic Symbol  Description  Truth.
Decision Structures and Boolean Logic
Announcements 1st homework is due on July 16, next Wednesday, at 19:00 Submit to SUCourse About the homework: Add the following at the end of your code.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design First Edition by Tony Gaddis.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 4 Decision.
Lesson 5: Working with Formulas and Functions Logical and 3D Formulas.
Homework Discussion Homework 4 (Glade Manual Chapter 4) More on Logical, Information and Text Functions.
PROBLEM SOLVING & ALGORITHMS CHAPTER 5: CONTROL STRUCTURES - SELECTION.
Chapter 7 Selection Dept of Computer Engineering Khon Kaen University.
Chapter 2 Excel Fundamentals Logical IF (Decision) Statements Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Principles of Programming - NI July Chapter 4: Basic C Operators In this chapter, you will learn about: Assignment operators Arithmetic operators.
Logical Functions and Conditional Formatting in Excel
Computer Information Technology Section 6-17
Numeric and Functional
Excel IF Function.
Boolean expressions and if-else statements
Lecture 3: Operators, Expressions and Type Conversion
Making Choices with if Statements
Bill Tucker Austin Community College COSC 1315
Chapter 4: Making Decisions.
Intro to C Tutorial 4: Arithmetic and Logical expressions
Topics The if Statement The if-else Statement Comparing Strings
Chapter 4 Select…Case Multiple-Selection Statement & Logical Operators
Chapter 4: Decision Structures and Boolean Logic
Chapter 4: Making Decisions.
Lecture 3 MIT 12043, Fundamentals of Programming By: S. Sabraz Nawaz
Chapter 4 Select…Case Multiple-Selection Statement & Logical Operators
Control Structures – Selection
Topics The if Statement The if-else Statement Comparing Strings
Relational Operators Operator Meaning < Less than > Greater than
Chapter 4: Decision Structures and Boolean Logic
Chapter 4 Select…Case Multiple-Selection Statement & Logical Operators
Chapter 7 Conditional Statements
Logical Operations In Matlab.
Chapter 5: Control Structure
Microsoft Visual Basic 2005: Reloaded Second Edition
Chapter 4: Control Structures I (Selection)
Conditional Logic Presentation Name Course Name
Chapter 4 Select…Case Multiple-Selection Statement & Logical Operators
Spreadsheets 2 Explain advanced spreadsheet concepts and functions
The System.exit() Method
SELECTIONS STATEMENTS
Chapter 4 Select…Case Multiple-Selection Statement & Logical Operators
Expressions.
Chapter 3: Selection Structures: Making Decisions
Boolean Expressions to Make Comparisons
Chapter 4: Boolean Expressions, Making Decisions, and Disk Input and Output Prof. Salim Arfaoui.
Spreadsheets Objective 6.02
Chapter 3: Selection Structures: Making Decisions
The Selection Structure
REACH Computer Resource Center
Spreadsheets Objective 6.02
Chapter 4 Select…Case Multiple-Selection Statement & Logical Operators
Module 3 Selection Structures 6/25/2019 CSE 1321 Module 3.
Chapter 4: Decision Structures and Boolean Logic
CSS161: Fundamentals of Computing
Boolean Expressions September 1, 2019 ICS102: The course.
3.0 - Design A software design specifies how a program will accomplish its requirements A design includes one or more algorithms to accomplish its goal.
Chapter 4 Select…Case Multiple-Selection Statement & Logical Operators
Presentation transcript:

Making Logical Decisions (IF-THEN-ELSE) 12/6/2018 Chapter 4 Making Logical Decisions (IF-THEN-ELSE)

12/6/2018 Chapter 4 – CW and HW Classwork – instructor exercises plus problems 4.1 and 4.4 Homework – problems 4.3, 4.6, 4.7

Chapter 4 – logical expressions 4.1 LOGICAL (BOOLEAN) EXPRESIONS Comparison Operators >, >=, <, <=, =, and <> (not equal to) The operators are used to connect various operands, to logical expression. Either TRUE or FALSE Example: C1 > 100 If the numerical value in cell C1 is greater than 100, the expression will be TRUE otherwise FALSE

Chapter 4 – Logical expressions Logical Expressions (AND, OR, NOT, XOR) Excepts multiple arguments Example AND(C1>0, C2>C1) Condition: TRUE only if the value in cell C1 is greater than 0 and the value in cell C2 exceeds the value in cell C1 Both condition must be TRUE for the AND function to be TRUE. NOT function reverses the value of its single argument.

Chapter 4 – Logical expressions Logical Expressions (AND, OR, NOT, XOR) Both values must be true to return a TRUE for AND Only 1 value must be true to return a TRUE for OR NOT reverses the effect of the logical expression

XOR FUNCTION XOR is the Exclusive OR function Format is XOR (logical1, logical2, logical3, …) with 1 to 254 conditions to be tested. Inputs can be logical values, arrays or references. If an array contains text or empty cells, those are ignored. If the range contains NO logical values, XOR returns the #VALUE! Error.

XOR and OR Truth table Truth table of OR: (1 is true, 0 is false) Truth table of XOR: Input 1 Input 2 Output 1 Input 1 Input 2 Output 1

Difference between OR and XOR XOR is TRUE if EXACTLY 1 of the operands (or an odd number of operands) is true. XOR is FALSE if the number of TRUE inputs is even.

Chapter 4 – MOD MOD: This function returns the remainder after dividing the value in cell C1 by the value in cell C2 i.e., MOD(C1,C2) Format is MOD(<number>,<divisor>) The sign of the value returned is ALWAYS the sign as the divisor. MOD(3,2) returns a 1. MOD(-3,-2) returns a -1. MOD(3,-2) returns a -1. MOD(-3,2) returns a 1.

Chapter 4 - MOD MOD(C1,2): Returns the remainder after the numerical value in cell C1 is divided by 2. Can use this function to determine if a number is ODD or EVEN. MOD(C1,2) is a number, then the number is ODD MOD(C1,2) is zero, then the number is EVEN.

Chapter 4 4.2 THE IF FUNCTION The IF function is used to carry out branching operations in EXCEL. The IF function requires three arguments: A logical expression followed by 2 values If the logical function is TRUE, then the IF function returns the first value. If it is FALSE, the function returns the second value. The values may be constants, numerical expressions, logical expressions, another IF function or strings.

Chapter 4 – example 1 Example 1 Suppose cell B5 contains the formula =IF(C1>100,50,C1/2) If the value in cell C1 exceeds 100, the value 50 will be placed in cellB5. Otherwise, (i.e., if the value in cell C1 does not exceed 100) then half the quantity in cell C1 will be placed in cell B5

Chapter 4 – example 2 Example 2 =IF(C1>100, “Too Big”, “OK”) If the value in cell C1 exceeds 100, “Too Big” will appear in cell B5 Otherwise, “OK” will appear in cell B5.

Chapter 4 4.3 NESTED IF FUNCTIONS IF function may be nested, one within another. The nested may be up to 65 deep. That is , as many as 64 IF functions may appear as arguments in other IF functions. Do Problem 4-1

Chapter 4 Example Cell A3 contains the temperature of a container of water, in degree Celsius. We can identify the state of the water, based upon its temperature, in either of the following ways: =IF(A3<0,”Ice” IF(A3<100,“Water”,”Steam”)) =IF(AND(A3>=0,A3<100),”Water”,IF(A3<0,”Ice”,”Steam”))

Chapter 4 A temperature less than 0 degree as “Ice” A temperature greater than or equal to zero but less than 100 degree Centigrade as “Water” A temperature greater than or equal to 100 degree Centigrade as “Steam.

Chapter 4 Can combine other logical expressions within the IF function. For example, in a piecewise function, the IF function can be combined with the AND operator to choose which function to evaluate. Do CW Problem 4-1. Note that format is IF(AND( ….. DO CW Problem 4-4

Chapter 4 – Example 4.1 Example 4.1 Student Grades Grade Rules: Overall Score Grade 90 and above A 80 to89.9….. B 70 to 79.9…. C 60 to 69.9….. D Below 60 F Formula: =IF(E2>=90,”A”,IF(E2>=80,”B”,IF(E2>=70,”C”,IF(E2>=60,”D”,”F”))))

Chapter 4 – Example 4.2 Example 4.2 Student Grades Revisited Modify the previous example to include pluses and minuses. Formula: =IF(E2>=97,”A+”,IF(E2>93,”A”,IF(E2>=90,”A-”,IF(E2>=87,”B+”,…..etc.))))

Chapter 4 – example 4-2 alternate Alternatively, we can decompose the problem into the following two parts: First determine an ordinary letter grade, Then we can determine whether to append a + or – using the following nested IF functions: IF MOD(E2,10)<=3,”-”,IF(MOD(E2,10)>=7,”+”,””)) Final Formula: =IF(E2>=90,”A”,IF(E2>=80,”B”,IF(E2>=70,”C”,IF(E2>=60,”D”,”F”))))&IF(MOD(E2,10)<=3,”-”,IF(MOD(E2,10)>=7,”+”,””))

Chapter 4 HOMEWORK Problems 4.3, 4.6 and 4.7 from textbook