You are on page 1of 13

INTRODUCTION TO

PSEUDOCODE
Sequential
Objectives

Identify popular Declaring variables


Read statements
terms and constants

Print/ Prompt
Calculation
statements
Term in Pseudocode

■ Start ■ If then

■ Stop ■ While do

■ Read/ get / accept/ input/ store ■ Repeat unit

■ Print / write / display ■ Declare

■ For do ■ Initialize
Declaration of variables

The process of stating to the compiler or individual reading that the following variables will be used and will be to this datatype.

Example: Declare two variables; fisrtname and totalCost with the datatypes of string and real respectively

solution:

Declare

Variables

firstname as String

totalCost as Real
Declaration of constants

The process of stating to the compiler or individual reading that the following constant will be used and will be to this datatype and

value.

Example: Declare two constants; pi and tax with the datatypes of real and the values 3.14 and 0.165 respectively

Declare

Constant

pi as real = 3.14

tax as real = 0.165


START STOP

After declaration, the keyword START is used and after the last line / statement the
keyword STOP is used. ( note some persons START then DECLARE this is also correct)
Examples
Declare
variable
Start
print “hello world”
Stop
Prompt Statements

In a pseudocode a prompt statement is used to instruct a user. The keyword PRINT, WRITE, DISPLAY is then followed by the

instruction/ message surrounded by double quotations. Prompt and print statements follow the same syntax. However, a prompt

statement is generally used to ask for data/ instruct users while the print statements is used to show/ display information.

Examples: 1) prompt the user to enter their name. 2) print the total cost of an item with a suitable messge.

solution:

write “Enter the user’s first name”

write “the total cost is $”, totalcost


Read Statements

In a pseudocode a read statement is used to accept data from the user. The keyword READ,

GET, ACCEPT, STORE is then followed by the variable that the data will be collects

Example: Accept the first name of a user.

Solution:

Read firstname
Calculation

A mathematical operation carried out. The operation is placed on the right side of the equal

sign and the variable to store the result is placed on the left side of the equal side.

Example: find the area of a rectangle given the length and width.

Solution:

Area = length * width


Example No.1

Design a pseudocode algorithm to calculate the area of circle. Accept the radius, calculate

and store the result in a variable and display the result.


Example No. 1 IPO

Input Process Output


Read r Read r Print ar
ar = 3.14 * (r*r)
Example No. 1 Pseudocode

Declare
variable
r, ar as real
Start
print “please enter the radius of the circle”
read r
ar = 3.14 * (r*r)
print “ the area of the circle is ” , ar
Stop
Class work

Activity – complete the following in your notebooks.

Design a pseudocode algorithm to;

1. Calculate the area of a right angled triangle. Accept the height and base of the triangle, calculate the area

and store the result in a variable and display the result.

2. Calculate the total cost of three store items. Accept the cost of the three store items, calculate the total,

store the result into a variable and display the result.

You might also like