Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
A garden centre sells turf by the square metre. Write a pseudocode algorithm that asks the user for the length and the width of a lawn in metres, works out the area, and outputs it with a message.
Then dry-run your algorithm for a lawn metres long and metres wide.
Cambridge pseudocode: keywords in capitals, names in mixed case, ← for assignment, INPUT and OUTPUT, IF ... THEN ... ELSE ... ENDIF, CASE OF ... OTHERWISE ... ENDCASE, FOR ... TO ... STEP ... NEXT, WHILE ... DO ... ENDWHILE, REPEAT ... UNTIL. DIV(a, b) is the whole-number quotient and MOD(a, b) the remainder.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, go through the solution one step at a time, and check each step against your own.
Plan. Prompt, two inputs, a process, an output.
A model answer.
OUTPUT "Enter the length and the width"
INPUT Length
INPUT Width
Area ← Length * Width
OUTPUT "Area: ", AreaStep 1. The dry run. Length is , Width is , so Area is .
Answer: the output is Area: 28, which means square metres.
Check. The names say what they hold, the keywords are in capitals, and the arrow is used for assignment. A line such as Area = Length * Width would not be the exam style.
Log in to join the discussion.
Loading…