Pseudocode Intro
Pseudocode Intro
Information Technology
Grade: 9
An algorithm is a sequence of precise
instructions which result in a solution.
• Pseudocode is a language similar to a programming language, but the rules are not as
stringent. Each statement must have the correct syntax. The syntax is the arrangement of
words in an instruction.
• Pseudocode is a logic development tool that uses English-like statements or clauses to
present the logical steps necessary to solve a problem.
• Data is facts and figures that can be
categorized as:
• 1. Data that is always the same value and
does not change, for example:
DATA AND DATA
• The number of hours in a day
TYPES
• The number of metres in a kilometre
• The name of the 3rd month in the year
• The speed of light.
• Data is facts and figures that can be
categorized as:
• 2. Data that changes or varies, for example:
DATA AND DATA • The cost of a product/item
TYPES • The salary of an employee
• The age of a person
• The number of persons in a city
• Data that does not change is called a constant. Some
constants may be numbers, e.g., 10, 34, 67, 9, 22,
CONSTANTS may be calculated, while others may be a series of
characters, e.g., Kingston, David, Monday, April.
• Character Constants
• Characters that are not likely to be calculated must be
enclosed in quotation marks to distinguish them from
numeric data, Such data is called a string.
• E.g., “11th Avenue, Cave Hill”
• “Jones”
TYPES OF
CONSTANTS • Numeric Constants
• Numeric constants are numbers that can be calculated.
Two types of numbers are being considered. Integers,
which are whole numbers. E.g., 10, 6, -20, and Real
numbers, which are numbers with a decimal point. E.g.,
11.5, 8.34, -5.60.
• Data that varies is what we call variable data. Such data
is given a name to represent the data that is being stored
and processed.
• Use names that gives a good representation of the data.
The name used is called the variable name. VARIABLE
• Variable names cannot contain spaces or begin with a
digit. Letters and abbreviations may be used. However, it
is recommended to keep the name to a reasonable lenght
EXAMPLES OF VARIABLES
• The user of the program can vary the value by changing the input value when variables are
used, whereas the user cannot change the value when constants are used.
• There is no need to modify the program when changes of values are required if variables
are used, whereas there is a need to do so if constants are used.
DATA INPUT AND STORAGE
INPUT INSTRUCTION
• Data to be processed must be entered into the computer and stored. Such data
may be entered from they keyboard.
• When creating the pseudocode for solving a problem, the commands used to
permit the entry of data are the words READ or INPUT.
• After which you will put the variable name(s) to represent the data to be
entered and stored. When more that one variable is present, a comma is used
to separate each variable
• The syntax is: READ <variable name>, <variable name>
• Write an instruction to input the quantity and price of
an item.
• Solution: READ QUANTITY, PRICE
Write an instruction
Write an instruction
to read the name of
to input the cost of
two(2) persons in a
a Laptop.
class.
PROMPTS
• While in the process of entering data, messages may appear on the screen
notifying the user of what data is to be entered. These messages are called
prompts or captions.
• Prompt statements begin with the command PRINT, followed by the message
enclosed in quotation marks.
• Example:
PRINT “Enter the name”
• PRINT “Enter the first grade”
• A read statement usually follows the prompt statement to facilitate the entry of
data corresponding to the prompt.
PRINTING INFORMATION
In most programs output is needed. Output
and be sent to the screen or the printer. When
developing the pseudocodes for solving a
problem, the command that is used to
produce the output is PRINT.
• This is necessary in order to give a description of the value of the variable that
is being printed.
• The syntax is: PRINT <string>, <variable>
• Example:
• PRINT “Cost”, COST
• In this example ”Cost” is a constant and COST is a variable. The word cost is
printed, as well as the value that is stored in the variable COST.
OUTPUTTING A
CONSTANT AND A • Write a structured algorithm to accept the price
of a product, then output the price.
VARIABLE AT THE • Solution: READ PRICE
SAME TIME • PRINT “Price”, PRICE
EXAMPLE
PROCESSING INVOLVING
CALCULATIONS
C A L CU L ATI O N S
USED FOR
P R O CE S S I N G D ATA
Calculation Symbol
• The result of the calculation is stored in the variable to the left of the equal (=)
sign also know as the assignment symbol. The variable is therefore assigned the
value resulting from the calculations.
• The value being assigned could be a constant or a variable or a calculation
• For example:
• SUM = 0 or STORE 0 TO SUM
• A = B. or STORE B TO A
• GRADE = “A” or STORE “A” TO GRADE
• TOTAL = A + B + C. or STORE A + B + C TO TOTAL
THE END