Lesson 4 PS and PD (Algorithm-IF Construct)
Lesson 4 PS and PD (Algorithm-IF Construct)
PROGRAM DESIGN
Algorithm-Pseudocode with IF
construct
OBJECTIVES:
General objective(s):
⦿ Understand when and how to include
IF statement within a pseudocode
algorithm.
IF Then Else:
⦿To read a number P. If the number is
greater than 50 it should add 20 to P.
If not, it should subtract 20 from P.
Print the result. They will be
encouraged to use their text book as
well as the internet to guide them.
ASSIGNMENT
⦿ Read and make notes on the following
Selection statements:
⦿ IF –THEN
⦿ IF-THEN-ELSE
IF-THEN STATEMENTS
Begin
Writeln ('Please enter mark');
READln (mark);
Print
READ Mark“Try harder next
READtime”
Mark Print “Excellent”
Print “Please see your
IF Mark>=80 Then teacher”
Print “Try harder next time”
Print “ Excellent”
Print “Please see your
teacher”
ELSE
ENDIF
EXAMPLE
PASCAL FOR
DEMONSTRATION
Program Exam_Results;
{Developer:Mrs. JaneDoe)
{Date:Nov. 19.2020}
{This program determines if Mark is greater than or equal to 80}
Var mark:real;
Begin
Writeln ('Please enter mark');
READln (mark);
Start
Print “Please enter a number”
Read P
IF P>50 THEN
Result🡨P+20
ELSE
Result🡨P-20
EndIF
Stop
IF THEN ELSE
Pseudocode Value_Of_P
Developer: Mrs. Jane Doe
Date: November 19,2020
This algorithm determines if a number is greater than or less 50.
Start
Print “Please enter a number”
Read P
IF P>50 THEN
Result1🡨P+20
Print “The result is:”, Result1
ELSE
Result2🡨P-20
Print “The result is:”, Result1
EndIF
Stop
TWO IF STATEMENTS
Pseudocode Value_Of_P
Developer: Mrs. Jane Doe
Date: November 19,2020
This algorithm determines if a number is greater than or less 50.
Start
Print “Please enter a number”
Read P
IF P>50 THEN
Result🡨P+20
ENDIF
IF P<50 THEN
Result🡨P-20
EndIF
Print “The result is:”, Result
Stop
NESTED IF(IF THEN ELSE
IF )
Pseudocode Value_Of_P
Developer: Mrs. Jane Doe
Date: November 19,2020
This algorithm determines if a number is greater than or less 50.
Start
Print “Please enter a number”
Read P
IF P>50 THEN
Result🡨P+20
ELSE
IF P<50 THEN
Result🡨P-20
EndIF
ENDIF
Print “The result is:”, Result
Stop
PASCAL FOR
DEMONSTRATION
Program Value_Of_P;
Developer: Mrs.Jane Doe}
{Date: November 19,2020}
{This algorithm determines if a number is greater than or less 50.}
Begin
Writeln ('Please enter a number');
Readln (P);
IF P>50 THEN
begin
Result:=P+20;
END
ELSE
Begin
Result:=P-20;
End;
Writeln ('The result is:', Result);
END.
PASCAL FOR
DEMONSTRATION
Program Value_Of_P;
{Developer: Mrs. Jane Doe}
{Date: November 19,2020}
{This algorithm determines if a number is greater than or less 50.}
Begin
Writeln ('Please enter a number');
Readln (P);
IF P>50 THEN
begin
Result1:=P+20;
Writeln ('The result is:', Result1);
END
ELSE
Begin
Result2:=P-20;
Writeln ('The result is:', Result2);
End;
END.
ACTIVITY
1. Students are awarded extra credit points depending on how
they perform in their coursework; if they received 80 or over,
they are given a bonus. Read the mark and add 1 to the total
number of credits if the condition is right and print the total.
NB:Accumulating: gradual gathering of something.
Total🡨Total + 1
6. Write a pseudocode algorithm to read two numbers and the user choice of
arithmetic operations. If user enter A perform Addition, M for Multiplication, D
for Division and S For Subtraction. Print two numbers, the user’s choice of
arithmetic operation and the result of the operation.