Learning Objectives
  • Use INPUT and OUTPUT correctly in pseudocode.
  • Explain sequence as execution in written order.
  • Use assignment to store calculations and input values.
  • Design clear user prompts and outputs for a short program.
Key Terms
Input
Data supplied to a program from a user or another source.
Output
Information produced by a program.
Prompt
An output message that tells the user what data to enter.
Sequence
The execution of instructions one after another in the order written.
Expression
A combination of values, identifiers and operators that produces one value.
Concatenated output
Output in which text and values are presented together.
Summary diagram
Summary Of The Main Ideas In This Lesson
Input And Output Statements

INPUT transfers a value supplied by the user into a variable. The variable should already be declared with a suitable type. OUTPUT presents text, values or the results of expressions.

A prompt should normally be output before input so the user knows what is required. A bare INPUT Age gives no instruction on the screen. OUTPUT “Enter age” followed by INPUT Age creates a clear interaction.

Output should include labels and units where needed. OUTPUT Total by itself may be ambiguous; OUTPUT “Total cost = $”, Total communicates the meaning.

Sequence

Sequence means instructions are executed in the order they are written unless selection, iteration or a subroutine changes the flow. A calculation cannot correctly use data that has not yet been input or initialised.

Changing the order can change the result. If a discount is calculated before the original price has been input, the expression uses an undefined value. If output occurs before the calculation, an old or uninitialised result is shown.

A simple program usually follows input-process-output, but the exact order depends on the task. Multiple inputs may be collected before processing, or processing may occur after each input.

Assignment And Expressions

The input statements assign entered values to Length and Width. The expression Length * Width is then evaluated, and the result is assigned to Area.

The assignment arrow is not used with INPUT because the INPUT statement itself identifies the receiving variable. Similarly, OUTPUT does not change stored data.

DECLARE Length : REAL
DECLARE Width : REAL
DECLARE Area : REAL

OUTPUT "Enter length"
INPUT Length
OUTPUT "Enter width"
INPUT Width
Area <- Length * Width
OUTPUT "Area = ", Area
Designing Clear Interaction

Prompts should state acceptable units or ranges when these matter. For example, “Enter mark from 0 to 100” is more useful than “Enter mark”.

Output can combine text and several values. A report might output a name, total and average on separate lines or in a clearly labelled format. The syllabus does not require sophisticated user-interface design, but output must be understandable.

Avoid overwriting input before it is needed. If OriginalPrice is required later, store a discounted value in a different variable or deliberately update it only when the original is no longer required.

Following A Sequence
Step Statement Effect
1 INPUT Hours Stores hours entered by the user
2 INPUT Rate Stores hourly rate
3 Pay <- Hours * Rate Calculates and stores pay
4 OUTPUT Pay Displays the calculated result
Worked Examples
Temperature Conversion

Question: Write a sequence that inputs Celsius and outputs Fahrenheit using F = C * 9 / 5 + 32.

  1. Declare Celsius and Fahrenheit as REAL.
  2. Output a prompt and input Celsius.
  3. Assign the calculated expression to Fahrenheit.
  4. Output a labelled result.

Answer: DECLARE Celsius : REAL; DECLARE Fahrenheit : REAL; OUTPUT “Enter Celsius”; INPUT Celsius; Fahrenheit <- Celsius * 9 / 5 + 32; OUTPUT “Fahrenheit = “, Fahrenheit.

Incorrect Order

Question: Explain the error in Total <- Price * Quantity followed by INPUT Price and INPUT Quantity.

  1. The calculation is executed first.
  2. Price and Quantity do not yet contain input values.

Answer: The inputs must occur before the assignment that uses them.

Examination Guidance
  • Include prompts when writing complete interactive pseudocode.
  • Keep the order of statements logically valid.
  • Use labels and units in output when the scenario needs them.
  • Declare variables before input or assignment.
  • Show the complete expression on the right side of assignment.
Common Mistakes
  • Using INPUT with a literal instead of a variable.
  • Writing an assignment arrow in an OUTPUT statement.
  • Calculating before input values exist.
  • Displaying an unlabelled number when several outputs are possible.
  • Assuming a sequence repeats without a loop.
Knowledge Check

1. What does INPUT do?

Answer: It reads a supplied value into a variable.

2. What does OUTPUT do?

Answer: It displays text, values or expression results.

3. What is sequence?

Answer: Execution of statements in the order written.

4. Why use a prompt?

Answer: To tell the user what data to enter.

5. Does OUTPUT change a variable?

Answer: No; it only presents information.