Download presentation
Presentation is loading. Please wait.
Published byDaniela Poole Modified over 9 years ago
1
Topics: Selection Statements
2
Processing Involving Selecting Instructions An instruction that allows deviation and selection to take place uses the ‘IF’ command. The IF statement contains a condition that is made up of three parts: Variable to be tested Relational operator Variable or constant to which the variable to be tested is compared to.
3
Relational Operators
4
If statements: IF-THEN IF-THEN-ELSE Flowchart Symbols: Decision making and branching Connector or joining two parts of a program. It is also used to connect sections of a flowchart when a flowchart is long and cannot fit on a page. A letter or digit can be placed in the small circle to indicate the link on the first page. Another identically labeled connector is placed on the next page to indicate the continuation of flow.
5
IF-THEN When one option is available and a selection may or may not be made, the IF-THEN is used. Pseudocode IF (condition) then One or more instructions which will be carried out if the condition is true ENDIF
6
Flowchart no yes Condition Statement - True
7
Problem 1: If a student’s grade is greater than 85%, then she is given 3 merits. Solution: Pseudocode IF (grade > 85) then merit = 3 ENDIF Flowchart no yes Examples IF-THEN grade > 85 merit = 3
8
Problem 2: Read the time. If the time is 11:00, output “Ring the bell”. Solution Pseudocode Read time IF (time = 11) then Print “Ring the bell” ENDIF
9
Problem 3: Read a number N. If N is greater than or equal to 100, add 10 to the number and display the result. Print the number. Solution: Pseudocode Read N IF (N >= 100) then result = N + 10 Print “Result is ” result ENDIF Print “Number is ” N
10
Problem Write a program that calculates and displays the revenue made by a minibus, which made 20 trips from Portmore to Kingston. Each passenger paid $120. If the revenue for the day exceeded $20,000.00, a bonus of 10% of the revenue is given to the driver. Compute and print the bonus amount. Input the number of passengers who traveled on each trip.
11
Requirements List the operations Write the Pseudocode Draw the Flowchart.
12
IF-THEN-ELSE When two options are available and a selection must be made, the IF-THEN-ELSE is used. Pseudocode IF (condition) then One or more instructions which will be carried out if the condition is true else One or more instructions which will be carried out if the condition is false ENDIF
13
Flowchart yes no Condition Statement - TrueStatement - False
14
Examples IF-THEN-ELSE Problem 1: If sales is greater than $7000, commission is $500 otherwise commission is $250 Solution: Pseudocode IF (sales > 7000) then commission = 500 else commission = 250 ENDIF Flowchart yes no Sales > 7000 Commission = 500Commission = 250
15
Examples IF-THEN-ELSE Problem 2: Read the age of a person. If age is greater than 35, output “old person” otherwise output “young person” Solution: Pseudocode Read age IF (age > 35) then Print “Old person” else Print “Young person” ENDIF
16
Problem 3: Input employee’s salary. If the salary is less than or equal to $44000, then a bonus of 15% is given, otherwise 10% is given. Calculate and display the bonus amount given. Solution: Pseudocode Read salary IF (salary <= 44000) then bonus = salary * 0.15 else bonus = salary * 0.10 ENDIF Print “Bonus amount is ” bonus
17
Problem A credit union pays 4% interest on shares that are greater than $25000 and 3% on all other shares. No interest is paid on deposits. Write a program that prompts the user to input a share a deposit. The program should calculate and output the interest amount and the total savings (Total savings = shares + deposit + interest amount).
18
Operations The operations are: 1. Input the number of passengers on each trip 2. Calculate the total number of passengers 3. Calculate the revenue for the day 4. Print the revenue 5. Determine if the bonus will be given 6. If the bonus is given, calculate the bonus amount 7. Print the bonus amount
19
Requirements List the operations Write the Pseudocode Draw Flowchart
20
Home Work Cambridge – Information Technology for CSEC Exercise 22 – Numbers 1 - 5
21
THE END
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.