Visual Logic, Schemes and Mind Maps of Logic

by a logical operator ... Returns the opposite of the condition ... Returns TRUE if the conditions have opposite values. Logical Operations ...

Typology: Schemes and Mind Maps

2022/2023

Uploaded on 02/28/2023

goldr4k3
goldr4k3 🇺🇸

4.4

(31)

286 documents

1 / 19

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
MAKING DECISIONS
Chapter 2
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13

Partial preview of the text

Download Visual Logic and more Schemes and Mind Maps Logic in PDF only on Docsity!

MAKING DECISIONS

Chapter 2

 If Statements are used to choose between actions

 A condition is a Boolean expression

 When executed, the condition is evaluated

◼ If the condition is true, control flows along the true arrow

◼ If the condition is false, control flows along the false arrow

 The IF statement ends where the true and false

branches reconnect

Condition False True

IF Statement

Input: First Begin First=Second Output: “The values are not the same” End Input: Second Output: “The values are the same” False (^) True A Simple IF Statement

Weekly Paycheck with Overtime Example

Long-Distance Billing Example

Test Two Numbers (Class Exercise)

 Read 2 numbers and determine if they are equal or one is greater than the other. If the values are equal print a message saying they are equal. If not, print a message saying which one is largest.

Operator Description NOT Returns the opposite of the condition AND Returns TRUE if and only if both conditions are TRUE OR Returns TRUE if at least one of the conditions is TRUE XOR Returns TRUE if the conditions have opposite values Logical Operations

Check on Compound Conditions

 Evaluate each of the following compound conditions. Assume X = 3 and Y = 7. Your answer should be true or false.

1. (x = 1) AND (Y = 7)

2. (X = 1) OR (Y = 7)

3. (X < Y) AND (Y > 10)

4. (X ^ 3 = 27) AND (Y MOD 2 = 1)

5. (X ^ 3 = 27) OR (Y MOD 2 = 1)

6. (X = 3) XOR (Y Mod 2 = 1)

7. (X = 1) XOR (Y = 7)

 Can we write (A<B<C)?  NO!!

  • You need to have explicit tests (A<B) and (B<C)
  • Join together with AND
  • Put each test in a parentheses Question

Example of Finding the Smallest Number  Smallest Number- Four Solutions

 Solution 1- Nested Conditions

 Solution 2- Compound Conditions

 Solution 3- Nested and Compound Conditions

 Solution 4- Placeholder Variable

Solution 2- Example

Solution 3- Example

Smallest of Five

 Write a program that displays the smallest of five input values that may include duplicate values.