Presentation is loading. Please wait.

Presentation is loading. Please wait.

SELECTION CONTROL STRUCTURE Prepared by: Careene McCallum-Rodney.

Similar presentations


Presentation on theme: "SELECTION CONTROL STRUCTURE Prepared by: Careene McCallum-Rodney."— Presentation transcript:

1 SELECTION CONTROL STRUCTURE Prepared by: Careene McCallum-Rodney

2 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…

3 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

4 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

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

6 LET’S CONTINUE …

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

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

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

10 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


Download ppt "SELECTION CONTROL STRUCTURE Prepared by: Careene McCallum-Rodney."

Similar presentations


Ads by Google