0% found this document useful (0 votes)
7 views3 pages

Pseudocode Worksheet 2 Answer

The document provides pseudocode examples for various programming levels, ranging from outputting student names to calculating totals and averages. It includes user input validation for numeric values and string lengths. Each level builds on the complexity of the tasks, demonstrating fundamental programming concepts.

Uploaded by

Nouman Shamim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views3 pages

Pseudocode Worksheet 2 Answer

The document provides pseudocode examples for various programming levels, ranging from outputting student names to calculating totals and averages. It includes user input validation for numeric values and string lengths. Each level builds on the complexity of the tasks, demonstrating fundamental programming concepts.

Uploaded by

Nouman Shamim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Pseudocode Practice 2

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:

FOR Counter <- 1 TO 12


Output StudentName[Counter]
NEXT

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 5 [without referring to slides]


StudentMark is an array that contains a list of marks from the Y10 students. Write a
program that finds the minimum and maximum marks. The starter code has been provided.
Pseudocode:
MaximumMark ← StudentMark[1]
MinimumMark ← StudentMark[1]
ClassSize ← 10
FOR Counter ← 2 TO ClassSize
IF StudentMark[Counter] > MaximumMark
THEN
MaximumMark <- StudentMark[Counter]
ENDIF
IF StudentMark[Counter] < MinimumMark
THEN
MinimumMark <- StudentMark[Counter]
ENDIF
NEXT COUNTER
Pseudocode Practice 2

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

You might also like