Pseudocode Worksheet 2 Answer
Pseudocode Worksheet 2 Answer
Level 1
StudentName is an array that contains a list of names (12 names) from Year 10. Write a
program to output the name of each student.
Pseudocode:
Answer:
Level 2
Ask user for a number. If the number is a negative value, output “negative”. If it is a positive
value, check if the number is 0, if so then output “zero”. If not then output “positive”.
Pseudocode:
Answer:
INPUT Number
IF Number < 0
THEN
OUTPUT “negative”
ELSE
IF Number = 0
THEN
OUTPUT “zero”
ELSE
OUTPUT “positive”
ENDIF
ENDIF
Level 3
ItemPrice is an array that contains a list of numbers representing the price of each item (the
array has a size of 15). Write a program to calculate the total price for all the items in the
array.
Pseudocode:
Total <- 0
FOR Counter <- 1 TO 15
Total <- Total + ItemPrice[Counter]
NEXT
Pseudocode Practice 2
Level 4
Create a dynamic array called ColorList that stores a list of strings (eg. “abcde”). Then, ask
the user iteratively for a color that they like. Store the user’s input into the ColorList array.
The program will terminate when the user enters the value “stop”.
Pseudocode:
Declare ColorList: ARRAY[1:] OF INTEGER
StopNow <- False
Counter <- 1
WHILE StopNow <> True DO
INPUT Color
ColorList[Counter] <- Color
INPUT Continue
IF Continue = “stop”
THEN
StopNow <- True
ENDIF
ENDWHILE
Level 6
Write pseudocode to input ten positive numbers (your program should not accept negative
numbers) and output the total and the average.
TOTAL <- 0
FOR Counter <- 1 TO 10
INPUT Number
WHILE Number < 0 DO
INPUT Number
ENDWHILE
TOTAL <- TOTAL + Number
NEXT
AVERAGE <- TOTAL / 10
OUTPUT TOTAL
OUTPUT AVERAGE
Validation Question 1
Write pseudocode to ask user for his/her nickname. The nickname must be between length
5 – 15. Otherwise, the user is prompted to input again.
(Hint: You may use the function length(yourVariable) to find the length of a string.)
INPUT Name
WHILE length(Name) < 5 OR length(Name) > 15 DO
INPUT Name
ENDWHILE