Presentation is loading. Please wait.

Presentation is loading. Please wait.

Making Logical Decisions (IF-THEN-ELSE)

Similar presentations


Presentation on theme: "Making Logical Decisions (IF-THEN-ELSE)"— Presentation transcript:

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

2 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

3 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

4 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.

5 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

6 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.

7 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

8 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.

9 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.

10 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.

11 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.

12 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

13 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.

14 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

15 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”))

16 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.

17 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 Note that format is IF(AND( ….. DO CW Problem 4-4

18 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 F Formula: =IF(E2>=90,”A”,IF(E2>=80,”B”,IF(E2>=70,”C”,IF(E2>=60,”D”,”F”))))

19 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.))))

20 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,”+”,””))

21 Chapter 4 HOMEWORK Problems 4.3, 4.6 and 4.7 from textbook


Download ppt "Making Logical Decisions (IF-THEN-ELSE)"

Similar presentations


Ads by Google