Pseudocode Notes
Pseudocode Notes
Pseudocode
★ Identifier
★ Variable
★ Constant
★ Input/ Read/Get
★ Output/ Display/ Print/ Write
★ Conditional Statements (IF, ELSE, ELSEIF
★ Loops (for, while, repeat-until)
IDENTIFIER
It is good practice to choose variable names that reflect the kind of data that is
being stored, e.g. num1, age1, sum, average etc.
CONSTANTS
Rule #3: variable names are Age, age, AGE, aGE, AgE Recommended:
case sensitive are all different Use a consistent case
Identify the constants and variables in the problem below. Circle the variables in
green and constants in red.
Susan owns and runs ‘British Virgin Islands’ (BVI) Boat Hire’ , that specializes in
renting out boats. There is a $3.50 charge per hour for rental. She needs a program
that reads in the number of hours that a boat has been rented, calculates and prints
Boolean Can contain only one of two possible TRUE or FALSE, YES or NO
values.
Activity
Suggest the most appropriate data type to store values related to EACH of the
following:
1. A person’s age
2. The weight of a piggy bank
3. The number of coins in a piggy bank
4. The total value of coins in a piggy bank
5. The number of items purchased.
6. The name of an item
7. Whether or not a piece of luggage is overweight
Mathematical Operators
- Subtraction 6 -2
/ Divide By 54/2
* Multiplication 4*9
AND
Expression A Expression B Result
False False False
OR
Expression A Expression B Result
NOT
Expression Result
False True
True False
Prompting Statements
● Used to get information from the user interacting with the program
to enter the required data for the program to work.
● This is usually a message displayed to the screen.
● The keywords WRITE, OUTPUT, PRINT or DISPLAY can be used.
Prompting Statement
Example:
Susan owns and runs ‘British Virgin Islands’ (BVI) Boat Hire’ , that specializes in
renting out boats. There is a $3.50 charge per hour for rental. She needs a program
that reads in the number of hours that a boat has been rented, calculates and
prints the total cost.
Solution: WRITE “Enter the number of hours you rented the boat.”
Instruction in
keyword quotation marks
NB: Try to begin your instruction with the word Enter. Instructions should be clear for
understanding.
Try on your own
OUTPUT
● Used to get data from outside the computer via an input device into a variable
for manipulation by the pseudocode.
● The keyword READ is used.
● Example:
Susan owns and runs ‘British Virgin Islands’ (BVI) Boat Hire’ , that specializes in
renting out boats. There is a $3.50 charge per hour for rental. She needs a program
that reads in the number of hours that a boat has been rented, calculates and prints
the total cost.
INPUT
Example:
Susan owns and runs ‘British Virgin Islands’ (BVI) Boat Hire’ , that specializes in
renting out boats. There is a $3.50 charge per hour for rental. She needs a program
that reads in the number of hours that a boat has been rented, calculates and prints
the total cost.
“label”
variable_name
Try on your own
OUTPUT
Susan owns and runs ‘British Virgin Islands’ (BVI) Boat Hire’ , that specializes in
renting out boats. There is a $3.50 charge per hour for rental. She needs a
program that reads in the number of hours that a boat has been rented,
calculates and prints the total cost.
SEQUENCE
● When we write programs, we assume that the computer executes the program
starting at the beginning and working its way to the end.
● This is a basic assumption of all algorithm design.
● We call this SEQUENCE.
START BEGIN
Sequence of instructions; Sequence of instructions;
Sequence of instructions; Sequence of instructions;
OR
Sequence of instructions; Sequence of instructions;
Sequence of instructions; Sequence of instructions;
STOP END
PSEUDOCODE STRUCTURE
START or BEGIN
Initialize variable (where necessary)
Prompting statement
Input Statement
Assignment Statement (s)
Output Statement
STOP or END
PSEUDOCODE STRUCTURE
Write a pseudocode algorithm that calculates and prints the total of two numbers.
START
TERMINATOR
STOP
Pseudocode Example
Susan owns and runs ‘British Virgin Islands’ (BVI) Boat Hire’ , that specializes in
renting out boats. There is a $3.50 charge per hour for rental. She needs a
program that reads in the number of hours that a boat has been rented,
calculates and prints the total cost.
Try on your own!
● Write a pseudocode algorithm to read three numbers and find their product,
sum and average.
Keep Practicing!