Defining Diagrams
Key Words used in Algorithm
⦿ PRINT -1. It is used to display an instruction
to the user for example a prompt statement
i.e. PRINT “Please enter your name”
2. It is used to display the result of Algorithm
i.e. PRINT “The total of two numbers is”,
sum
INPUT – this used to read or accept a value
that will be entered into a computer by a
user.
⦿ For example INPUT name
What is a Prompt Statement?
⦿ It is a description or instruction that tells the user
what to do.
⦿ For example in the problem statement: Write an
algorithm that prompts the user to enter the
price and quantity of an item and then find the
total price.
⦿ The only way the user will know what to do is if
you tell them
⦿ 1) PRINT “ Enter the price of the item”
⦿ 2) PRINT “Enter the quantity”
Activity 1
Identify the prompt statements in the
following algorithm.
⦿ Write an algorithm that accepts four
grades and compute and print the
average grade.
Variables
⦿ These are containers in memory that are
used to store inputs in a computer.
⦿ Just as cooking chicken requires you to
put meat in a container to be washed,
seasoned and cooked each input in
computer requires a container (variable).
Also note that for every purpose there is
the need for a container.
Identifying the need for
variables
⦿ Write an algorithm that accepts the price
and quantity of an item. Print the total
price.
⦿ You will need a container (variable) to
store the price, quantity and the total
price.
Activity 2
⦿ Identify the variables in the following
problem statement.
⦿ Write an algorithm that accepts 4 grades
and find the average grades.
Let’s look at naming variables
×A name of a variable cannot have a
space even if you are using two words.
✔ You may join the words for example
Totalpriceor use an underscore between
words for example Total_price
× You are not allowed to use any other
symbol other than an underscore (_). That
is you cannot use #, @,!,&,* when naming
a variable.
× You cannot start a variable name with a
number for example 1number, 2 number
✔ However you may start with an
underscore (_) for example _price or
with a letter num1
× A variable cannot be a keyword for
example INPUT, READ, BEGIN, START
Activity 3
Identify and name the variables in the
problem statement below.
⦿ Write an algorithm that accepts 4 grades
and find the average grades
Reconstructing our Defining Diagram
⦿ In lesson 1 and 2 we learnt that all problem
statement will have an input, output, some
storing and a process (recipe) to solve the
algorithm.
⦿ Input: what we are asked to enter
⦿ Output: what our result should be
⦿ Storing: what our variables will be
⦿ Process: The steps we will follow to achieve the
desired output