Double entry check in pseudocode

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Double entry check in pseudocode

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which pseudocode loop condition completes a double entry check for two passwords?
A UNTIL Password1 = Password2
B UNTIL Password1 <> Password2
2. How many INPUT statements does a double entry check need for one value?
A Two: INPUT Password1 and INPUT Password2
B One: INPUT Password1 only
3. Which loop type suits a double entry check, where the user must enter the values at least once?
A FOR ... TO ... NEXT
B REPEAT ... UNTIL
4. Where should the message for a mismatch be placed?
A After the loop, so it is always shown once
B Inside the loop, in an IF Password1 <> Password2 statement
5. Which message belongs in the IF statement of a double entry check?
A OUTPUT "Passwords do not match, try again"
B OUTPUT "Passwords match"

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1UNTIL Password1 = Password2 AREPEAT INPUT Password1 INPUT Password2 UNTIL Password1 = Password2
2OUTPUT "Passwords do not match" BThe loop repeats until the two typed values are equal, so the double entry check passes
3A double entry check asks for the same value twice using two INPUT statements CTells the user the two entries were different so they must type them again
4The two entries are compared inside a REPEAT loop that only ends when they are equal DThe condition uses <> so the loop stops when the entries are different. It should use = so it stops only when they match.
5UNTIL Password1 <> Password2 EINPUT Password1 INPUT Password2
6REPEAT INPUT Password1 UNTIL Password1 = Password1 FThere is only one INPUT and the variable is compared with itself, so it is always true. There must be a second INPUT into Password2 and the condition must compare Password1 = Password2.

Definitions

UNTIL Password1 = Password2

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
______ INPUT Password1 INPUT Password2
2.
INPUT Password2 _____ Password1 = Password2
3.
UNTIL Password1 _ Password2
4.
IF Password1 __ Password2 THEN OUTPUT "Passwords do not match" ENDIF
5.
IF Password1 <> Password2 THEN ______ "Passwords do not match" ENDIF

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A WHILE
B INPUT Password1
C INPUT Password2
D OUTPUT "Passwords must match"
E UNTIL Password1 = Password2
Question 2
A REPEAT
B READ Password1
C INPUT Password2
D OUTPUT "Passwords must match"
E UNTIL Password1 = Password2
Question 3
A OUTPUT "Choose a password"
B REPEAT
C INPUT Password2
D INPUT Password2
E UNTIL Password1 = Password2
Question 4
A REPEAT
B INPUT Password1
C INPUT Password2
D UNTIL Password1 <> Password2
Question 5
A OUTPUT "Type it twice"
B LOOP
C INPUT Password1
D INPUT Password2
E UNTIL Password1 = Password2

Answer Key

Double entry check in pseudocode
Section A: Quick Questions
Q1
A — UNTIL Password1 = Password2
Q2
A — Two: INPUT Password1 and INPUT Password2
Q3
B — REPEAT ... UNTIL
Q4
B — Inside the loop, in an IF Password1 <> Password2 statement
Q5
A — OUTPUT "Passwords do not match, try again"
Section B: Match the Pairs
Q1
UNTIL Password1 = Password2 → The loop repeats until the two typed values are equal, so the double entry check passes
Q2
OUTPUT "Passwords do not match" → Tells the user the two entries were different so they must type them again
Q3
A double entry check asks for the same value twice using two INPUT statements → INPUT Password1 INPUT Password2
Q4
The two entries are compared inside a REPEAT loop that only ends when they are equal → REPEAT INPUT Password1 INPUT Password2 UNTIL Password1 = Password2
Q5
UNTIL Password1 <> Password2 → The condition uses <> so the loop stops when the entries are different. It should use = so it stops only when they match.
Q6
REPEAT INPUT Password1 UNTIL Password1 = Password1 → There is only one INPUT and the variable is compared with itself, so it is always true. There must be a second INPUT into Password2 and the condition must compare Password1 = Password2.
Section C: Definitions
Q1
UNTIL Password1 = Password2 — Double entry check: INPUT the value twice inside a REPEAT loop and stop only when both are equal. Output a message if they do not match, so typing mistakes are caught.
Section D: Fill in the Blanks
Q1
REPEAT INPUT Password1 INPUT Password2
Q2
INPUT Password2 UNTIL Password1 = Password2
Q3
UNTIL Password1 = Password2
Q4
IF Password1 <> Password2 THEN OUTPUT "Passwords do not match" ENDIF
Q5
IF Password1 <> Password2 THEN OUTPUT "Passwords do not match" ENDIF
Section E: Spot the Error
Q1
A — A double entry check uses a REPEAT ... UNTIL loop so both values are entered at least once. Line 1 should be REPEAT, not WHILE, because the loop ends with UNTIL.
Q2
B — READ is not a Cambridge pseudocode keyword. The first entry must be read with INPUT Password1.
Q3
C — Line 3 should store the first entry in Password1. Reading into Password2 twice means Password1 never gets a value, so the two entries cannot be compared properly.
Q4
D — The loop must repeat until the two entries are equal. Using <> would stop the loop when the entries are different, which is the opposite of a double entry check. It should be UNTIL Password1 = Password2.
Q5
B — LOOP is not a Cambridge pseudocode keyword. The loop must start with REPEAT to match the UNTIL at the end.