1 / 10

SELECTION CONTROL STRUCTURE

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.

totie
Download Presentation

SELECTION CONTROL STRUCTURE

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. SELECTION CONTROLSTRUCTURE 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…

  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” ENDIF END 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 No price <= lunch_money Yes PRINT “Sorry, you need more money. HUSH” PRINT “You can get cooked lunch” END

  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 … Do you think you have a better understanding of selection control Structure so far?

  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. A CONDITION is an expression that when evaluated gives either a TRUE or FALSE.

  8. IF-THEN-ELSE CONSTRUCTS IF ( condition ) THEN <statement 1> <statement 2> …. ELSE <statement 1> <statement 2> …. 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. Attempt this example

  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 Represent this psedococe using flowchart.

More Related