Lect 8 Problem Solving With Decision Making
Lect 8 Problem Solving With Decision Making
Decision Structures allow computers to choose one action out of the two
Flowchart :
A condition can be one of four things:
• A logical expression : an expression that uses
logical operators (AND, OR, and NOT)
• An expression using relational operators: greater
than, less than, greater than or equal to, less than or
equal to, equal to, and not equal to
• A variable of the logical data type (True or False)
• A combination of logical, relational, and
mathematical operators.
Logical operators are used to link more than one
condition together
Nested If/Then/Else Instructions
Input = Number of hours he/she has worked (Hours), and R (per hour)
Analysis:
• Normal payment = Rate* Hours
• If overtime then payment = Normal payment + 1.5 (Extra hours *Rate)
= Rate * Hours + 1.5 (Extra hours *Rate)
= Rate * Hours + 1.5 ( (hours-40) * Rate)
For Normal payment Hours=40
= Rate *40 + Rate * 1.5 (Hours – 40)
Nested If/Then/Else Instructions
Straight-through logic :
o All of the decisions are processed sequentially, one after the other.
o There is no Else part of the instructions.
o The False branch always goes to the next decision, and the True branch goes to the next
decision after the instructions for the True branch have been processed.
Straight Through Logic
• Decisions making using straight-through logic, all conditions are tested.
• To test a condition means to process a condition to get a True or False resultant.
• Straight-through logic is the least efficient of all types of decision logic because all the
decisions must be processed.
Example: Ticket rate based on age group
Nested If/Then/Else Instructions
Flowchart Pseudocode
Algorithm
Positive Logic
Positive logic :
o Positive logic is the easiest type for most people to use and understand.
o It is the way we think.
o Positive logic always uses nested If/Then/Else instructions.
o When you use positive logic, you are telling the computer to follow a set of instructions
and continue processing if the condition is True; if the condition is not True, then the
computer processes another decision
Positive Logic
Pseudocode
Algorithm Flowchart
Positive Logic
Flowchart
Positive Logic
Flowchart
To convert from positive logic to negative logic or vice versa, do the following:
1. Change all < to > =
2. Change all < to >
3. Change all > to < =
4. Change all >= to <
5. Change all == to <> (Not equal to)
6. Change all < > to == (Not equal to)
7. Interchange all of the Then set of instructions with the corresponding Else set of instructions.
Logic Conversion