Pseudocode
Input, process, output
What is an input?
An input is data or information being entered/taken into a program before it is
processed in the algorithm
An input can come from a variety of sources, such as:
o User - keyboard, mouse, controller, microphone
o Sensors - temperature, pressure, movement
Values are input using the INPUT command
INPUT <identifier>
What is a process?
A process is a doing action performed in the algorithm that transforms inputs into the
desired output. The central processing unit (CPU) executes the instructions that define
the process
An example would be:
o Comparing two numbers
o Calculating an average
What is an output?
An output is the result of the processing in an algorithm and usually the way a user
can see if an algorithm works as intended
An output can take various forms, such as:
o Numbers - result of calculations
o Text
o Images
o Actions - triggering events
Values are output using the OUTPUT command
OUTPUT <value(s)>
More than one value can be output in the same command when separated by commas
OUTPUT "First name: ", Fname, "Surname: ", Sname
Example 1 - Area of a shape
A user wants to write a program to calculate the area of a shape
Input Process Output
Length
Length X width Area
Width
// Calculate the area of a rectangle
INPUT Length
INPUT Width
Area ← Length * Width
OUTPUT "The area is ", Area
Example 2 - Average test score
A teacher wants to calculate the average mark achieved on a test amongst students in a
class
The teacher needs to enter how many students in the class and for each students a score
out of 50
Input Process Output
TotalScore = TotalScore + score per
Number of
student Average
students
Average = TotalScore / Number of mark
Score per student
students
// Calculate the average test score for a class
DECLARE TotalScore : INTEGER
DECLARE Score : INTEGER
DECLARE NumberOfStudents : INTEGER
DECLARE Average : REAL
TotalScore ← 0
INPUT NumberOfStudents
FOR StudentIndex ← 1 TO NumberOfStudents
OUTPUT "Enter score for student ", StudentIndex
INPUT Score
TotalScore ← TotalScore + Score
NEXT StudentIndex
Average ← TotalScore / NumberOfStudents
OUTPUT "The average score is ", Average
Programming constructs
What is sequence?
Sequence refers to lines of code which are run one line at a time
The lines of code are run in the order that they written from the first line of code
to the last line of code
Sequence is crucial to the flow of a program, any instructions out of sequence
can lead to unexpected behaviour or errors