SELECTION CONTROL STRUCTURE Prepared by: Careene McCallum-Rodney.

Slides:



Advertisements
Similar presentations
MONTEGO BAY HIGH SCHOOL INFORMATION TECHNOLOGY THE EXCEL IF FUNCTION.
Advertisements

What IF?.
Selection (decision) control structure Learning objective
Understanding the Three Basic Structures
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 9 Decisions, Decisions, Decisions.
Subject: Information Technology Grade: 10
Objectives AND logic OR logic Evaluating compound conditions with multiple logical operators Precedence when combining AND and OR operators Efficiency.
1 CSC103: Introduction to Computer and Programming Lecture No 8.
ITEC113 Algorithms and Programming Techniques
CS107 Introduction to Computer Science Loops. Instructions Pseudocode Assign values to variables using basic arithmetic operations x = 3 y = x/10 z =
Computer Science 1620 Programming & Problem Solving.
Chapter 4 MATLAB Programming Logical Structures Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
PROGRAMMING, ALGORITHMS AND FLOWCHARTS
Programming Logic and Design Sixth Edition
Branching and Conditions CSIS 1595: Fundamentals of Programming and Problem Solving 1.
Chapter 3 Making Decisions
CPS120: Introduction to Computer Science Decision Making in Programs.
Selection Structure If... Then.. Else Case. Selection Structure Use to make a decision or comparison and then, based on the result of that decision or.
Programming Logic and Design, Second Edition, Comprehensive
PAGES:51-59 SECTION: CONTROL1 : DECISIONS Decisions.
CHAPTER 3 SELECTION STRUCTURE.
Selection Control Structures. Simple Program Design, Fourth Edition Chapter 4 2 Objectives In this chapter you will be able to: Elaborate on the uses.
1 CSC103: Introduction to Computer and Programming Lecture No 7.
ANALYSIS AND ALGORITHM DESIGN - IV. Repeat statements/looping/counting/iterations It is often necessary to repeat certain parts of a program a number.
CHAPTER 4: Selection Control Structure. Objectives  Use the relational comparison operators  Learn about AND logic  Learn about OR logic  Make selections.
Saeed Ghanbartehrani Summer 2015 Lecture Notes #5: Programming Structures IE 212: Computational Methods for Industrial Engineering.
If…else statements. Boolean Expressions Boolean expression - An expression whose value is either true or false true = 1 false = 0 Datatype: boolean.
Chapter 5: Making Decisions
Agenda Basic Logic Purpose if statement if / else statement
Programming with App Inventor Computing Institute for K-12 Teachers Summer 2012 Workshop.
A item is marked 25% off and then you are given an additional discount of 10%. What will you pay? Are receiving a total of 35% off? Explain why or why.
Lecture 2 Conditional Statement. chcslonline.org Conditional Statements in PHP Conditional Statements are used for decision making. Different actions.
Computer Programming TCP1224 Chapter 5 The Selection Structure.
More Python!. Lists, Variables with more than one value Variables can point to more than one value at a time. The simplest way to do this is with a List.
CPS120: Introduction to Computer Science Decision Making in Programs.
Topic: Control Statements. Recap of Sequence Control Structure Write a program that accepts the basic salary and allowance amount for an employee and.
Topics: Selection Statements. Processing Involving Selecting Instructions An instruction that allows deviation and selection to take place uses the ‘IF’
8. DECISION STRUCTURES Rocky K. C. Chang October 18, 2015 (Adapted from John Zelle’s slides)
3.1.3 Program Flow control Structured programming – SELECTION in greater detail.
Computer Science 101 If Statement. Python Relational Operators.
Decision Making and Branching
Programming Logic and Design Fourth Edition, Comprehensive Chapter 5 Making Decisions.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Why Repetition? Read 8 real numbers and compute their average REAL X1, X2, X3, X4, X5, X6, X7, X8 REAL SUM, AVG READ *, X1, X2, X3, X4, X5, X6, X7, X8.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
Flow Charts And Pseudo Codes Grade 12. An algorithm is a complete step-by- step procedure for solving a problem or accomplishing a task.
Programming Logic and Design Fifth Edition, Comprehensive Chapter 4 Making Decisions.
ANALYSIS AND ALGORITHM DESIGN - III
Exercise : Write a program that print the final price of purchase at a store where everything costs exactly one dollar. Ask for the number of items purchased.
Chapter 4 MATLAB Programming
Pseudocode Upsorn Praphamontripong CS 1110 Introduction to Programming
CS1371 Introduction to Computing for Engineers
Chapter 5: Control Structure
The order in which statements are executed is called the flow of control. Most of the time, a running program starts at the first programming statement,
Chapter 4: Decision Structures and Boolean Logic
Selection By Ramin && Taimoor
Introduction To Robot Decision Making
Control Structure Senior Lecturer
Understanding the Three Basic Structures
Chapter 4: Decision Structures and Boolean Logic
Selection Statements.
Chapter 5: Control Structure
Introduction To Robot Decision Making
Relational Operators.
CHAPTER 5: Control Flow Tools (if statement)
Chapter 4: Decision Structures and Boolean Logic
REPETITION Why Repetition?
Control Structures.
Presentation transcript:

SELECTION CONTROL STRUCTURE Prepared by: Careene McCallum-Rodney

Introduction It becomes necessary at times to ask questions and take certain actions based on a particular condition. You can allow the computer to do a particular action based on a certain condition. For example, you are given $200 for your lunch money. To determine what to buy, you will need to know what is available and the price of the item. If you would like to buy a large cooked lunch, your money might not be sufficient. Consider the following pseudocode… Consider the following pseudocode…

Introduction cont. START DECLARE price, lunch_money AS real PRINT “Please enter the price of the cooked lunch” READ price PRINT “What is your lunch money?” READ lunch_money IF (price <= lunch_money) THEN PRINT “You can get the cooked lunch” ELSE PRINT “Sorry, you need more money. HUSH” ENDIFEND DISCUSS THIS PSEUDOCODE WITH YOUR TEACHER

Introduction cont. This is how the flowchart will look for the previous pseudocode. START PRINT “Please enter the price of lunch and the lunch money you now have” READ price, lunch_money price <= lunch_money PRINT “You can get cooked lunch” PRINT “Sorry, you need more money. HUSH” END YesNo

CLASS ACTIVITY This is a 10-minute exercise Arrange yourselves in groups of 3s. Identify a SIMPLE situation where a decision is necessary. Do not be complicated, keep it very simple. Construct a pseudocode for your situation. AFTERWARDS Each group will present to the class their situation and the pseudocode for it.

LET’S CONTINUE …

Making Comparisons It sometimes become necessary to make comparisons. Do you agree? Well if you are going to make comparisons, you should be knowledgeable of the comparators that can be used. Relational OperatorsMeaning = Equal to >Greater than <Less than > =Greater than or equal to < =Less than or equal to != OR Not equal to A CONDITION is an expression that when evaluated gives either a TRUE or FALSE.

IF-THEN-ELSE CONSTRUCTS IF ( condition ) THEN …. ELSE …. ENDIF If the condition is true, the statements between the THEN and ELSE will be executed. If the condition is false, the statements between the ELSE and ENDIF will be executed.

Example A company gives out bonuses based on the amount of income generated by their sales representative per month. Once the income is greater than $5,000, a bonus of 10% of the generated income is given to the employees. Otherwise, the bonus is 3% of the income. Read the income generated and print the bonus.

Answer to Example Pseudocode START DECLARE income, bonus AS real PRINT “Please enter your income” READ income IF income > 5000 THEN bonus = income * (10/100) ELSE bonus = income * (3/100) ENDIF PRINT “Your bonus is”, bonus END