Algo
Algo
Recapitulation
• Remember that an algorithm is a formal sequence of instructions of
how to solve a problem.
• In essence it is the recipe for solving a problem
Declaring variables
• In lesson 3 we learnt how to identify and name variables. Today we
will learn how to declare variables.
• When declaring a variable you give a suitable name and identify the
data type.
What is a datatype?
• This is simply saying what type of data will your variable (container)
hold.
• Just as how you have a bag (container) to hold books, a wallet
(container) to store money and cards, a bottle (container) to store
water.
• There are 4 basic data types in algorithm.
Data types
Textual data is data that may include a combination of letters,
symbols and numbers.
• Character or Char –can be in the form of a single letter or symbol
• String- group of characters
Numerical Data is data that made of two main types:
• Integers- refer to numbers that don’t have decimal points. E.g.
5,20,-25,8700
• Real-refer to numbers with a decimal point. E.g. 10.25,-6.98
Boolean data is data that must be true or false .
Whether you are married or not.
Absent or Present
Let’s declare some variables
• Write an algorithm that accepts the price and quantity of an item and
print the total price.
STOP
Cont’d writing pseudocode
• Take all the instructions that are under the P column in your defining
diagram and insert between START and STOP.
START
PRINT “Enter the quantity”
INPUT quantity
PRINT “Enter the price”
INPUT price
Total_Price=Price*Quantity
PRINT “The total price is”, Total_Price
STOP
Cont’d writing pseudocode
• Declare the variables immediately under the keyword START
START
• Declare price as REAL
• Declare Quantity as INTEGER
• Declare Total Price as REAL
• Write an algorithm that accepts 4 grades and print the average grade.