Professional Documents
Culture Documents
PSEUDOCODE
Sequential
Objectives
Print/ Prompt
Calculation
statements
Term in Pseudocode
■ Start ■ If then
■ Stop ■ While do
■ 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
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:
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
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:
Design a pseudocode algorithm to calculate the area of circle. Accept the radius, calculate
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
1. Calculate the area of a right angled triangle. Accept the height and base of the triangle, calculate the area
2. Calculate the total cost of three store items. Accept the cost of the three store items, calculate the total,