Logical reasoning in practice
Example: Are you old enough to drive?
Look at this simple pseudocode Also written as pseudo-code. A method of writing up a set of instructions for a computer program using plain English. This is a good way of planning a program before coding.algorithmA sequence of logical instructions for carrying out a task. In computing, algorithms are needed to design computer programs. for working out if you are old enough to drive a car:
OUTPUT 'How old are you?'
INPUT user inputs their age
STORE the user's input in the age variable
IF age > 17 THEN OUTPUT 'You are old enough to drive a car!'
ELSE IF age < 17 THEN OUTPUT 'You are too young to drive a car.'This algorithm has a fault.logical reasoningThe application of rules to problem solving. can be used to determine what the fault is.
There are two conditionIn computing, this is a statement or sum that is either true or false. A computation depends on whether a condition equates to true or false. in this algorithm. The first checks if age is greater than 17. The second checks if age is less than 17.
We can use logical reasoning to predict the outcomes of this algorithm. Logically, it is clear that a person’s age could be greater than 17, less than 17, or could actually be 17. From this, it is possible to use these values in the algorithm to make predictions:
- A rule exists to check if age is greater than 17. If age is greater than 17, the algorithm will output ‘You are old enough to drive a car!’
- A rule exists to check if age is less than 17. If age is less than 17, the algorithm will output ‘You are too young to drive a car.’
- No rule exists to check if age is equal to 17. If age is equal to 17, there will be no output.
Logic tells us that either a rule needs to be added, or the existing rules need to be changed. The algorithm can be fixed by either:
- adding a new rule – ELSE IF age = 17 OUTPUT ‘You are old enough to drive a car!’
- or amending the first rule – IF age >= 17 OUTPUT ‘You are old enough to drive a car!’
Either solution would work.