Questions which require you to answer in or a are used to examine your ability to write in logical ways. The examiner will check your answer to see that it meets the meets the requirements outlined in the questions, and to see if you have shown that you have a good understanding of how to structure code.

## Things to remember when answering pseudo-code questions

• You do not need to memorise the Edexcel pseudo-code - you will be given a copy of it during the examination.
• You can use any version of pesudo-code that you are familiar with.
• You do not have to be completely accurate in your pseudo-code, but what you write does have to make sense.
• Do not worry if you feel you cannot complete all of the pseudo-code algorithm. Depending on the mark scheme, you may still gain some marks.
• Remember, there are many different ways to solve a problem, so there will be many alternative algorithms.

The following question has been taken from an Edexcel past paper. It reflects the type of question that may appear in an exam paper.

## Example question

The HappyPetBox Company needs a program to validate customer .

Valid customer identifiers are nine characters long, ending with three uppercase letters.

Here are four examples of valid customer identifiers.

• 836154JSA
• 579317NOY
• 958375MEB
• 294713PUC

Write an algorithm that will:

• take a potential customer identifier from the user
• if input is “Q”, allow the user to quit the program
• if the potential customer identifier is too short, then tell the user
• if the last three characters do not follow the rules, then tell the user
• allow the user to keep entering customer identifiers

A sample output is shown.

Write an algorithm to meet the requirements.

Use pseudo-code or a programming language with which you are familiar.

[9 marks]

## How to tackle the question

Pseudo-code questions are worth a large number of marks and are therefore more complex than many other questions. Make sure you read the whole question carefully. This example answer is going to use pseudo-code rather than write the answer in an actual programming language.

After reading the whole question carefully, look at the requirements. This will help you to decompose the problem.

For this question, you need to write an algorithm that will:

• take a potential customer identifier from the user

The program will need to read in the customer identifier. The identifiers contain both letters and numbers, so the program will need to read in a . In pseudo-code you could write:

RECEIVE identifier FROM (STRING) KEYBOARD

• if input is “Q”, then allow user to quit the program

The program will need to check if the input contains just a “Q”, and if it does, quit the program. This is a selection, so you can do this using an IF .

• if the potential customer identifier is too short, then tell the user

The program will need to check if the entered identifier is nine characters long (the length required is at the start of the question). If the length isn’t nine characters (again, a selection), the program needs to output an error. In pseudo-code you could write:

IF LENGTH (identifier) <> 9 THEN

     SEND ‘The customer identifier is not nine characters long’ TO

DISPLAY

END IF

• if the last three characters do not follow the rules, then tell the user

The start of the question tells you that the last three characters must be uppercase letters. Again, there is selection here, but it also requires you to loop through the last three characters and see if any of them are greater than or equal to ‘A’ and less than or equal to ‘Z’. The question tells you how many times the algorithm has to loop so you should use a FOR loop. If the program finds a character that isn’t an uppercase letter, it will need to issue an error.

In pseudo-code you could write:

SET badAlpha TO FALSE #this is a flag that will be changed to TRUE if a non-uppercase letter is found

FOR count FROM 6 TO 8 DO

     IF (NOT (identifier[count] >= ‘A’ AND identifier[count] <= ‘Z’)) THEN

          SEND ‘Bad character in last 3 characters found’ TO DISPLAY

          SET badAlpha TO TRUE

     END IF

IF badAlpha = FALSE THEN

     SEND ‘Final three characters are valid’ TO DISPLAY

END IF

• allow the user to keep entering customer identifiers

This tells you that you’ll need a loop (iteration) of some form so that the user keeps being asked for identifiers to check until Q is entered.