50% found this document useful (2 votes)
574 views

Pseudocode Worksheet 1 Answer

The document provides examples of pseudocode problems of varying difficulty levels. It includes problems asking the user for input, performing calculations, using arrays and loops. The final section gives examples of common pseudocode solutions like totaling values in an array and counting elements that meet a condition.

Uploaded by

Fatima Khurram
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
50% found this document useful (2 votes)
574 views

Pseudocode Worksheet 1 Answer

The document provides examples of pseudocode problems of varying difficulty levels. It includes problems asking the user for input, performing calculations, using arrays and loops. The final section gives examples of common pseudocode solutions like totaling values in an array and counting elements that meet a condition.

Uploaded by

Fatima Khurram
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Pseudocode Practice

Write codes that fulfill the following requirements:

Difficulty Level: Easy


1. Ask the user for a name. After that, OUTPUT “Hello, (the name where the user has typed
in).

INPUT Name
OUTPUT “Hello “ + Name

2. Create a variable call MEALCOST. Assign a value of 10 to it.


Then, create another variable call MEALSELLINGPRICE, which is twice the value of
MEALCOST.
Then, create another variable call TAX, which is 6% of the MEALSELLINGPRICE.
Lastly, create a variable call TOTALPRICE, which is the sum of MEALSELLINGPRICE and TAX.

MEALCOST <- 10
MEALSELLINGPRICE <- 2 * MEALCOST
TAX <- MEALSELLINGPRICE * 0.06
TOTALPRICE <- MEALSELLINGPRICE + TAX

---------------------------------- BADGE EARNED!! Current rank: Beginner ---------------------------------

Difficulty Level: Medium


3. DECLARE a dynamic array, named it as Y10CLASS, which will be used to contain a list of
names.

DECLARE Y10Class : ARRAY[1:] OF STRING

4. Design a program that asks a user to INPUT two numbers. The program will multiply the
numbers together (hint: you need to create a variable that stores the product). If the
product is larger than 100 it outputs the message “Greater than 100”. If not, it does nothing.

INPUT N1
INPUT N2
Product <- N1 * N2
IF Product > 100
THEN
OUTPUT “Greater than 100”

--------------------------------- BADGE EARNED!! Current rank: Amatuer --------------------------------

1
Pseudocode Practice

Difficulty Level: Hard


5. Fries are sold in the canteen at $3 each, if 10 fries are bought then the discount is
5%, if 20 fries are bought the discount is 15%. No more than 30 fries can be bought
in a single transaction (hint: A while loop can be used for validation (eg. Fries
number cannot be less than 1 or more than 30).

(Do not use CASE OF, use IF ... ELSE ... THEN instead)

You are asked to design a program that can automatically calculate the cost of the
purchase. Print out the cost. The program will keep repeating until a user INPUT a
value "stop". Write the pseudocode for this program.

WHILE Continue <> “STOP” DO

WHILE NumberOfFries < 1 OR NumberOfFries > 30 DO


INPUT NumberOfFries

IF NumberOfFries > 10
THEN
IF NumberOfFries > 20
THEN
Discount <- 0.15
ELSE
Discount <- 0.05
ENDIF
ELSE
Discount <- 0
ENDIF

TOTALFRIESPRICE <- NumberOfFries * 3 * (1 – Discount)


OUTPUT TOTALFRIESPRICE

INPUT Continue

------------------------------------ LEVEL UP!! Current rank: Professional ----------------------------------

2
Pseudocode Practice

Standard methods of solution

1. Totaling

StudentMark [1:10]
70 75 80 60 70 65 75 90 95 100

Write the pseudocode to find the total mark:

Total <- 0
ClassSize <- 10
FOR Counter <- 0 TO 10
Total <- Total + StudentMark[Counter]
NEXT

2. Counting

StudentMark [1:10]
70 75 80 60 70 65 75 90 95 100

Write the pseudocode to find the number of students who pass (mark > 50) the exam.

PassCount <- 0
ClassSize <- 10
FOR Counter <- 0 TO 10
IF StudentMark[Counter] > 50
THEN
PassCount <- PassCount + 1
NEXT

You might also like