ICT Level 2 Unit 7 - Algorithm & FlowChart
ICT Level 2 Unit 7 - Algorithm & FlowChart
What is Algorithm?
Algorithms are used by humans and computers. A computer follows algorithms exactly as they
are written.
Key Point
• An algorithm must be clear.
• An algorithm must be in the correct order (sequence).
What is a Bug?
An error or mistake in an algorithm is called a ‘Bug’.
What is Debugging?
Debugging is the process of finding and fixing those bugs to make sure the algorithm works
correctly.
What is Decomposition?
Decomposition is the process of breaking a large, complex problem into smaller, more manageable
parts. Before writing an algorithm, we often use decomposition to understand the different parts of a
task.
1. START
2. Unscrew the toothpaste lid.
3. Add a pea-sized amount of toothpaste to the brush.
4. Turn on the tap and wet the brush.
5. Brush all teeth thoroughly.
6. Repeat scrubbing until teeth are clean.
7. Rinse your mouth and the brush.
8. Dry your mouth.
9. STOP.
1. START
2. ---------------------------------------------------------------------------------
3. ---------------------------------------------------------------------------------
4. ---------------------------------------------------------------------------------
5. ---------------------------------------------------------------------------------
6. STOP
Can you put these steps in the correct sequence? Write numbers 1 to 6 next to each step.
--------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------
Question 2: Give one reason for producing an algorithm before writing a program. (1 mark)
--------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------
Question 3: It is important to debug every algorithm when complete. What does the term 'debug'
mean? (1 mark) Tip: Think about finding and fixing mistakes.
Answer below:----------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------
What is Pseudocode?
Pseudocode is a way of writing out an algorithm using simple English-like statements. It is not a
real programming language, so the computer cannot run it, but it helps programmers plan the
logic before writing real code (like Python).
Basic Rules:
Keyword Meaning
START / BEGIN Marks the Beginning of the algorithm.
STOP / END Marks the End of the algorithm
INPUT Get data from the user
OUTPUT / DISPLAY /
Shows a message or the **value of a variable** on the screen
PRINT
Comment
• Single-line comments: // ….
• Multi-line/Block comments: /* ….. * /
START
OUTPUT "Hello!"
STOP
What is a Variable?
• Variable Name: The label used to identify the box (e.g., UserAge).
• Value: The actual data kept inside the box (e.g., 12).
Data Types
Choosing the correct Data Type is essential for storing data correctly.
Real (or Float) Numbers with decimal points. 3.14, 98.6, 0.5
String (Text) A sequence of characters. (Always put in "quotes") "Apple", "Year 6", "123"
START
DECLARE Name : STRING
Name := "Thomas"
OUTPUT Name
STOP
Exercise 1: Data Type Identification ( Write the correct Data Type next to each value.)
1. 42 : (___________________________)
1. ☐ User Age
2. ☐ User_Age
3. ☐ 1st_Name
4. ☐ Player1
1. Start
2. Set the variable Score to 100
3. Display the value of Score
4. Stop
Rewrite this algorithm using pseudocode.
START
______________________________
______________________________
______________________________
STOP
Exam Practice
Answer: ----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------
Question 2: Complete the table by identifying the most suitable data type. for each item of data. (2
marks)
START
DECLARE Score : INTEGER
SET score TO 100
OUTPUT score
STOP
(a) State the name of the process used to find and fix errors in an algorithm. (1 mark)
----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------
In Lesson 2, we learned how to SET a variable manually. However, most programs need to ask the
user for information. We use the INPUT keyword for this.
Example: Instead of SET Name TO "Mg Mg", we use:
INPUT Name (The computer waits for the user to type their name)
Arithmetic Operators
Computers are excellent at calculation. In Pseudocode and Python, we use specific symbols for
math:
Note: The Modulo (%) operator only gives you the remainder of a division. For example, 10
divided by 3 is 3 with a remainder of 1. So, 10 % 3 = 1.
When a calculation has many parts, the computer follows a specific order, similar to BIDMAS in
Math. The Letters stand for Brackets, Indices, Division and Multiplication, Addition and
Subtraction. In programming we follow this hierarchy:
B ()
Order of operations
I x2
D ÷
M x
A +
S -
Example: 5 + 2 * 10 The computer does 2 * 10 first (20), then adds 5. Result = 25 (Not 70!)
Below are three examples of applying BIDMAS to calculations, using a range of operators.
36 - (10 + 2) * 3 = (6 + 6) / 3 + 8 (14 - 4) =
Brackets first Brackets first
3 * (2 + 4) =
36 – 12 * 3 = 12 / 3 + 8 * 10 =
Brackets first
Then the then the division and
3 * 6 = 18
multiplication multiplication
36 – 36 = 0 4 + 80 = 84
START
DECLARE num1, num2, result : INTEGER
num1 := 10
num2 := 20
SET result TO num1 + num2
OUTPUT result
STOP
START
DECLARE Length, Width, Area : INTEGER
INPUT Length
INPUT Width
SET Area TO Length * Width
OUTPUT Area
STOP
Scenario A:
1. START
2. DECLARE Number1, Number2, Result : INTEGER
3. INPUT Number1 (User types 20)
4. INPUT Number2 (User types 5)
5. SET Result to Number1 / Number2
6. OUTPUT Result
7. STOP Final Output: (___________________________)
Scenario B:
1. START
2. DECLARE X, Y, Z : INTEGER
3. SET X to 10
4. SET Y to 2
5. SET Z to (X + Y) * 3
6. OUTPUT Z
7. STOP Final Output: (___________________________)
1. Start
2. ______________________________
3. set distance to 50
4. INPUT speed
5. set time to distance / speed
6. ______________________________
7. Stop
Write a pseudocode algorithm that asks the user for their Birth Year, calculates their Age, and
displays it. (Hint: Age = Current Year - Birth Year)
START
______________________________
______________________________
______________________________
______________________________
______________________________
STOP
Exam Practice
Question 1: A programmer uses the following instruction: SET Total to 10 + 5 * 2 State the value of
Total. (1 mark)
___________________________________________________
___________________________________________________
___________________________________________________
___________________________________________________
___________________________________________________
___________________________________________________
___________________________________________________
Question 3: Complete the pseudocode to calculate the average of two numbers. (2 marks)
START
DECLARE Num1, Num2, Average: INTEGER
INPUT Num1
INPUT Num2
SET Average TO (_________ + _________) / 2
_________________ Average
STOP
In programming, the computer follows instructions line by line, from top to bottom. If the steps are
out of order, the algorithm will fail even if the commands are correct.
A Logical Error is a bug where the program runs without crashing, but it produces the wrong
result. This usually happens because the math or the logic is incorrect.
Example:
Just like English has grammar rules, programming languages have Syntax.
Definition: Syntax is the set of rules that tell us how to write code correctly, including correct
spelling, symbols, and order.
The Rule: Computers are very strict. If the syntax is wrong (for example, wrong spelling or missing
symbols), the program may not run.
A Trace Table is a tool used to track the value of variables at every step of an algorithm. It helps us
see exactly where the logic goes wrong.
1. START
2. DECLARE X : INTEGER
3. SET X TO 5
4. SET X TO X + 10
5. OUTPUT X
6. STOP
Trace Table
1. START
2. ______________________________
3. ______________________________
4. ______________________________
5. ______________________________
6. ______________________________
7. STOP
Look at the pseudocode below. The goal is to calculate the discounted price of a toy.
(Discount = Price - 5).
START
DECLARE Price : REAL
DECLARE FinalPrice : REAL
SET Price TO 20
SET FinalPrice TO Price + 5
OUTPUT finalprice
STOP
Exam Practice
______________________________________________________________
______________________________________________________________
What is Flowchart?
A Flowchart is a diagram that shows the step-by-step logic of an algorithm using different shapes.
While Pseudocode uses English text, a Flowchart uses Visual Symbols. It helps programmers
"see" the logic before writing the actual code.
Standard Flowchart Symbols: Every shape in a flowchart has a specific meaning. You must use
the correct shape for the correct action.
Diamond:
Decision
A diamond indicates a decision
1. Always start with a START symbol and end with a STOP symbol.
2. Use Flow Lines (arrows) to connect the shapes.
3. Arrows should point in the direction the data is moving.
4. Instructions inside the shapes should be clear and short.
STOP
1. START
2. DECLARE Side : INTEGER INPUT Side
3. INPUT Side
4. SET Area TO Side * Side
5. OUTPUT Area
SET Area = Side * Side
6. STOP
OUTPUT Area
STOP
OUTPUT "Enjoy
your coffee"
STOP
Instead of converting a whole code, let’s practice drawing the symbols for specific actions. In the
box below, draw the correct flowchart symbol for each instruction:
1. Instruction: START
o Your Drawing: (____________________)
5. Instruction: STOP
o Your Drawing: (____________________)
Scenario: A student wants to create a flowchart that asks for a person's Birth Year, calculates their
Age, and then Displays the result. However, they have made three (3) logic and symbol errors.
START
INPUT BirthYear
OUTPUT Age
STOP
Task: Find the three errors and explain why they are wrong.
• Error 1: ________________________________________
o Why? ________________________________________
• Error 2: ________________________________________
o Why? ________________________________________
• Error 3: ________________________________________
o Why? ________________________________________
A student tried to draw a flowchart to calculate a total score, but they made several mistakes with
the shapes!
Scenario:
• They used a Rectangle to ask for the user’s name: INPUT Name
• They used a Parallelogram for a calculation: Total = Score1 + Score2
• They used Rectangle for the very first step: START
Task: Identify the mistakes and state which symbols SHOULD have been used.
Exam Practice
Question 1: Which flowchart symbol is used to represent an assignment, such as SET Count TO
0? (1 mark) Tick (✓) the correct answer.
A) ☐ Oval
B) ☐ Rectangle
C) ☐ Parallelogram
D) ☐ Arrow
Answer: ________________________________________
Question 3:
Give one advantage of using a flowchart rather than pseudocode to show an algorithm. (1 mark)
Answer:________________________________________
Before we start drawing, let's remember which Pseudocode words belong to which Flowchart
shapes:
Step-by-Step Translation
To convert Pseudocode to a Flowchart, follow the flow of the code line by line.
Flowchart Steps:
1. START
OUTPUT "Hello "+ UserName
2. OUTPUT "Please enter your name: "
3. INPUT UserName
4. OUTPUT "Hello " + UserName
5. STOP
STOP
Pseudocode: START
START
DECLARE num1, num2, total : INTEGER
OUTPUT "Enter Number1: "
OUTPUT "Enter Number1: "
INPUT num1
OUTPUT "Enter Number2: "
INPUT num2
SET total TO num1 + num2 INPUT num1
OUTPUT "Total Sum=" + total
STOP
OUTPUT "Enter Number2: "
Flowchart Steps:
1. START
2. OUTPUT "Enter Number1: " INPUT num2
3. INPUT num1
4. OUTPUT "Enter Number2: "
5. INPUT num2 SET total TO num1 + num2
6. SET total TO num1 + num2
7. OUTPUT "Total Sum=" + total
8. STOP
OUTPUT "Total Sum=" + total
STOP
Look at Example 2 again. If the user provides the following inputs, what will be the Final Output?
• Input num1: 10
• Input num2: 5
Final Output: ____________________
Pseudocode:
START
DECLARE Dollars, Rate, Kyats : REAL
OUTPUT "Enter Dollars Amount: "
INPUT Dollars
SET Rate TO 3500
SET Kyats TO Dollars * Rate
OUTPUT Kyats
STOP
Remember, in Flowcharts, setting a value (like SET Rate TO 3500) and calculations (like Dollars *
Rate) are both types of processing. You should put them inside Rectangles (Process symbols)!
Task: Rearrange these steps into the correct Logic Sequence so the algorithm works correctly.
1. ______________
2. ______________
3. ______________
4. ______________
5. ______________
In Lesson 4, we learned that the order of steps is very important. Look at the steps below. If you put
them in a flowchart, which one must come first?
A) SET Result TO A + B
B) INPUT A, B
C) OUTPUT Result
Answer: Step ______ must come first, because the computer needs the numbers before it can
calculate them. This is called the IPO Model (Input-Process-Output).
Exam Practice
Question 1: A programmer needs to ask a user for their age. Which symbol and keyword should
they use? Tick (✓) the correct answer. (1 mark)
A) ☐ Rectangle / SET
B) ☐ Parallelogram / INPUT
C) ☐ Oval / START
D) ☐ Diamond / IF
Question 2: Draw a flowchart for an algorithm that asks for a student’s name and their score, then
Displays “Score saved for ” followed by the name. (3 marks)
(Draw your flowchart here)
Question 3: In a flowchart, why must an INPUT symbol come before a PROCESS symbol that uses
that data? (2 marks)
Answer: ________________________________________
Question 4: Draw a flowchart snippet that shows the computer calculating BMI = Weight / (Height *
Height). Assume the inputs have already been taken. (2 marks)
(Draw your flowchart here)
• The Rule: A Diamond always has ONE entrance but TWO exits.
• The Exits: One exit must be labelled YES (or True) and the other NO (or False).
• The Question: Inside the diamond, we write a condition (e.g., Age > 18?).
Visualization: Think of the Diamond as a "Fork in the road". The data travels down, hits the
Diamond, answers the question, and then must choose one path. It cannot go both ways!
Relational Operators
Inside the Diamond, we compare things using special math symbols.
Symbol Meaning Example
= or == Is Equal to? 9 = 13
!= or <> Not equal to 9 <> 13
> Is Greater than? 9 > 50
< Is Less than? 9 < 25
>= Greater than OR Equal to 9 >= 18
<= Less than OR Equal to 9 <= 17
Logical Operators
Sometimes, checking one thing is not enough. Imagine a login screen. To enter, you need the
correct Username AND the correct Password. If one is wrong, you cannot enter.
In Pseudocode, we use three main words to combine conditions:
1. AND
2. OR
3. NOT
Pseudocode:
START
START
DECLARE UserPass : STRING
OUTPUT "Enter Password: "
OUTPUT "Enter Password: "
INPUT UserPass
IF UserPass = "Secret" THEN
OUTPUT "Access Granted"
ELSE INPUT UserPass
OUTPUT "Access Denied"
END IF
STOP
" "
Flowchart Steps:
1. START
OUTPUT "Access OUTPUT "Access
2. OUTPUT "Enter Password: " Denied"
Granted"
3. INPUT UserPass
4. Decision: UserPass = "Secret"
* If Yes: OUTPUT "Access Granted"
* If No: OUTPUT "Access Denied"
5. STOP STOP
Flowchart Steps:
Sometimes, we need to make more than one choice. This is called a Multiple Selection.
Pseudocode: START
START
DECLARE Mark : INTEGER
OUTPUT “Enter your mark: ” OUTPUT "Enter your mark: "
INPUT Mark
IF Mark >= 80 AND Mark <= 100 THEN
OUTPUT "Grade A" INPUT Mark
ELSEIF Mark >= 40 AND Mark <80 THEN
OUTPUT "Grade B"
ELSE
OUTPUT "Grade C"
ENDIF
STOP
1. START
2. OUTPUT "Enter your mark: " OUTPUT "Grade B" OUTPUT "Grade C"
3. INPUT Mark
4. Decision 1: Mark >= 80 AND Mark <= 100?
* If Yes: OUTPUT "Grade A! "
* If No: Move to the next Decision.
5. Decision 2: Mark >= 40 AND Mark < 80? STOP
* If Yes: OUTPUT "Grade B! "
* If No: Move to the next Decision.
6. Process (Else): OUTPUT "Grade C".
7. STOP
START
OUTPUT "Enter Day Name: "
DECLARE Day : STRING
OUTPUT "Enter Day Name: "
INPUT Day
IF Day = "Saturday" OR Day = "Sunday" THEN INPUT Day
OUTPUT "It is the Weekend! No School!"
ELSE
OUTPUT "Go to School"
ENDIF
STOP
1. START
2. OUTPUT "Enter Day Name: "
3. INPUT Day
4. Decision: Day = "Saturday" OR Day = "Sunday" STOP
* If Yes: OUTPUT "It is the Weekend! No School!"
* If No: OUTPUT "Go to School"
5. STOP
Look at the "Pass or Fail" Flowchart logic above. Predicting the output for different inputs.
User Input (Score) Condition: Score >= 40? Path Taken (YES / NO) Final Output Message
39 ______ NO _________________
Pseudocode:
START
DECLARE Temperature : INTEGER
(Draw your flowchart here - Hint: Make sure your Diamond has two clear arrows)
• Rule: If Age is under 12, Ticket Price is $5. Otherwise (Else), Ticket Price is $10.
Flowchart Steps:
1. START
2. OUTPUT “Enter your age: ”
3. INPUT Age
4. DECISION: is Age <12?
* If Yes: SET Price TO ___________
* If No: SET Price TO ___________
5. OUTPUT "Please pay: " + Price
6. STOP
Task: How many Decision Diamonds will you need for this flowchart? Answer: ______________
Exam Practice
Question 1: Which flowchart symbol is used to ask a question like "Is X > 10?"? (1 mark)
Tick (✓) the correct answer.
A) ☐ Parallelogram
B) ☐ Rectangle
C) ☐ Diamond
D) ☐ Circle
Question 2: Look at this condition: IF Time >= 12. State whether the result is TRUE (Yes) or
FALSE (No) for the following inputs:
• Time = 9 : __________
• Time = 12 : __________
• Time = 15 : __________
Question 3: Draw a flowchart symbol and arrows for the following logic: "If Battery is less than
20%, Display 'Low Battery'." (2 marks) (Draw a Diamond with a condition inside, and a YES arrow
leading to a Parallelogram)
(Draw your flowchart here)
Question 5: Write a pseudo code program to determine vowel or not and accepted one character
from the keyboard. Draw a flowchart.
(Draw your flowchart here)
What is Iteration?
Iteration is the process of repeating a sequence of instructions until a specific condition is met. In
computer science, we commonly refer to this as a Loop.
Instead of writing the same code many times, we use a loop to make the algorithm shorter and more
efficient
Not all loops are the same. We decide when to stop based on two rules:
1. FOR Loop
* Used when the number of iterations is known in advance.
2. WHILE Loop
* Test the condition before action.
* Commands may not be executed at all, if condition is false.
Starting State;
WHILE condition
statements to be executed;
increment / decrement;
END WHILE
Starting State;
REPEAT
Commands
Increment / decrement
UNTIL (condition)
A flowchart loop doesn't have a special new symbol. Instead, it uses a Decision Diamond and a
Flow Line (Arrow) that goes back up.
• The Increment (Counter): Usually, we use a variable (like Count = Count + 1) to keep track
of how many times we have looped.
• The Arrow: Notice the arrow goes from the bottom back to the top. This creates a circle or
cycle.
Pseudocode:
START
SET num TO 1
DECLARE num : INTEGER
FOR num := 1 TO 5 STEP 1
OUTPUT num
END FOR No
is num <= 5 ?
STOP
Yes
Flowchart Steps:
OUTPUT num
1. START
2. SET num TO 1
3. Decision: is num <= 5 ?
SET num TO num +1
* If Yes (True): Continue to STEP 4
* If No (False): Go to STOP
4. OUTPUT num
5. SET num TO num + 1 STOP
6. Loop Line: Go back to STEP 3
7. STOP
Pseudocode:
START SET num TO 1
DECLARE num : INTEGER
num := 1
WHILE num <= 5 DO
OUTPUT num No
is num <= 5 ?
num := num + 1
END WHILE
Yes
STOP
OUTPUT num
Flowchart Steps:
1. START
2. SET num TO 1 SET num TO num +1
3. Decision: is num <= 5 ?
* If Yes (True): Continue to STEP 4
* If No (False): Go to STOP
4. OUTPUT num STOP
5. SET num TO num + 1
6. Loop Line: Go back to STEP 3
7. STOP
Pseudocode:
START
DECLARE num : INTEGER SET num TO 1
num := 1
REPEAT
OUTPUT num OUTPUT num
num := num + 1
UNTIL num > 5
STOP SET num TO num +1
Flowchart Steps:
No
1. START is num > 5 ?
2. SET num TO 1
3. OUTPUT num Yes
4. SET num TO num + 1
5. Decision: is num > 5 STOP
• If No (False): Loop Line: Go back to STEP 3
• If Yes (True): Continue to STEP 6
6. STOP
Pseudocode:
START INPUT pass
DECLARE pass : STRING
OUTPUT "Enter Password: "
INPUT pass
WHILE pass <> "secret" No is pass <>
OUTPUT "Wrong! Try Again" "secret"
INPUT pass
END WHILE Yes
OUTPUT "Welcome"
STOP OUTPUT "Wrong!
Try Again"
OUTPUT "Welcome!"
Flowchart Steps:
INPUT pass
1. START STOP
2. OUTPUT "Enter Password: "
3. INPUT pass
4. Decision: is pass <> "secret"
* If Yes (True): OUTPUT “Wrong! Try Again”. → Go back to Step 3(Input)
* If No (False): OUTPUT “Welcome!”. → Go to STOP.
Note: See how the NO arrow goes back up? That forces the user to try again. The program will
never end until they type "Secret".
1. A program that prints the "Happy Birthday" song for every student in a class of 20.
• Type: ____________________
• Type: ____________________
• Type: ____________________
• Type: ____________________
Draw a flowchart for an algorithm that displays the message "Hello World" exactly 10 times. (Hint:
Use a counter starting at 1 and a decision diamond to check if the count is <= 10).
Follow the flowchart logic below and write down the final output.
1. SET Num TO 0
2. SET Num TO Num + 2
3. OUTPUT Num
4. Is Num == 6?
• NO: Go back to Step 2.
• YES: Stop.
First Pass: 2
Second Pass: _____
Third Pass: _____ (Stop)
A student wrote this algorithm to count down from 10 to 1. But it runs forever! Why?
The Code:
1. SET Count TO 10
2. OUTPUT Count
3. SET Count TO Count + 1 ← (Look closely here!)
4. IF Count = 0 THEN STOP
5. ELSE GO TO Step 2
Exam Practice
Question 1: Which flowchart feature creates a loop? Tick (✓) the correct answer. (1 mark)
Question 2: Draw a flowchart snippet for a loop that asks a user to "Input a Number" and repeats
as long as the number is less than 0. (3 marks)
(Draw your flowchart here)
Answer: _________________________________________________________
A Trace Table is a technique used to test an algorithm on paper to make sure it works correctly.
When you follow an algorithm line-by-line without using a computer, it is called a "Dry Run".
Example Layout:
Variable Variable
Step Instruction (Code) OUTPUT (Display)
A B
1 SET A TO 5 5 0
2 SET B TO 10 5 10
3 OUTPUT "Result is " + B 5 10 "Result is 10"
User Input
Condition: Score >= 40? Output Message
(Score)
80 True (Yes) "You Passed!"
Trace tables are most useful for Loops (Lesson 8). Let's see how variables change during a loop.
The Algorithm:
1. SET X TO 1
2. REPEAT
3. OUTPUT X
4. SET X TO X * 2 (Multiply by 2)
5. UNTIL X > 5
1 1 1 2 False (Repeat)
2 2 2 4 False (Repeat)
3 4 4 8 True (STOP)
A student wrote a program to count from 1 to 3. But the output is wrong. Use a trace table to find
the bug.
Answer:
The variable Score is never updated (no SET Score TO Score + 1). This creates an Infinite Loop.
Exam Practice
Question 2: Trace the following algorithm and state the final output. (2 marks)
SET N TO 5
SET N TO N + N
SET N TO N – 2
OUTPUT N
Final Output: ______________
Question 3: Why is a trace table useful before you start coding? (2 marks)
Answer: ________________________________________________________________________
• A) A new variable.
• B) A new step or iteration of the loop.
• C) The final result only.
Question 5: Draw a Trace Table for a loop that runs 3 times, adding 5 to a Total (starting at 0) each
time. (3 marks)
In programming, we often confuse these two actions. Let's clear it up using a "Shopping Cart"
example.
Logic Add a fixed amount (usually +1). Add a variable amount (e.g., + Price).
Before using a variable for counting or totalling, you must set its starting value to 0.
• Why? To clear any "garbage values" (old data) left in the computer’s memory. If you don't
start at 0, your final answer will be wrong.
Pseudocode:
START
DECLARE Total, Price, Round : INTEGER
SET Total TO 0 // Initialization
FOR Round := 1 TO 3 STEP 1
OUTPUT "Enter Price:"
INPUT Price
SET Total TO Total + Price // Totalling Logic
END FOR
OUTPUT "Your total is: " + Total
STOP
A teacher wants to enter marks for 10 students and Count how many students passed
(Marks >= 50).
Pseudocode:
START
DECLARE PassCount, i, mark : INTEGER
SET PassCount TO 0 // Start counter at 0
FOR i := 1 TO 10 STEP 1
OUTPUT “Enter your mark: ”
INPUT mark
IF mark >= 50 THEN
SET PassCount TO PassCount + 1 // Counting Logic
END IF
END FOR
OUTPUT "Number of students who passed: " + PassCount
STOP
Flowchart Logic:
1. START
2. SET PassCount TO 0 (Start counter at 0)
3. Loop 10 Times:
o INPUT Mark
o Decision: Is Mark >= 50?
▪ YES: SET PassCount TO PassCount + 1 (Add 1 to counter).
▪ NO: Do nothing.
4. End Loop
5. OUTPUT PassCount
6. STOP
Average Calculation
Complete the logic for an algorithm that adds up all numbers from 1 to 5.
Goal: Calculate the Average score of 3 students. (Hint: Average = Total Score / 3)
Steps:
1. START
2. SET Total TO 0
3. Loop 3 Times:
• INPUT Score
• SET Total TO __________________ (Hint: Logic for totalling)
4. End Loop
5. SET Average TO Total / 3
6. OUTPUT Average
7. STOP
Exam Practice
Question 1: Which of the following represents a Totalling statement? (1 mark)
• A) SET X TO X + 1
• B) SET Total TO 0
• C) SET Total TO Total + NewValue
• D) OUTPUT Total
Question 2: Why is it important to set a "Total" variable to 0 before a loop starts? (2 marks)
Answer:__________________________________________________________________
• A) Counting
• B) Totalling
Question 5: Draw a flowchart snippet that checks IF Score < 40, then adds 1 to a variable named
FailCount. (3 marks)
In exams and real life, you are often given a flowchart with "holes" in it. To fill them correctly, follow
these three steps:
1. Read the Goal: What is the algorithm trying to achieve? (e.g., "Check a password" or
"Calculate a discount").
2. Trace the Path: Follow the arrows with your finger. Does the flow stop suddenly? Does it
skip a step?
3. Spot the Gap: Look for what's missing. Is it a Question (Diamond), an Action (Rectangle),
or a Result (Parallelogram)?
Even professional programmers make these mistakes! Look out for these errors in your exercises:
The Infinite Loop A loop that has no "exit" condition. The program runs forever.
Task: Look at the diagram below and fill in the missing pieces (A, B, and C).
START
No
A?
B?
C?
Exam Practice
Question 1: Why must every Decision Diamond have exactly two exit arrows? (2 marks)
Answer: ________________________________________________________________________
Question 2: Look at the logic below. Which shape is in the wrong order? (2 marks)
START
INPUT Price
STOP
A) Rectangle
B) Parallelogram
C) Diamond
D) Oval
2. What is an "Algorithm"?
A) Input
B) Process
C) Output
D) Storage
4. Which loop is best when you know EXACTLY how many times to repeat?
5. What is the error called when a program runs but gives the wrong answer?
A) Syntax Error
B) Logic Error
C) Hardware Error
D) User Error
Answer: ___________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
SET X TO 5
SET Y TO 10
SET X TO Y
SET Y TO X
OUTPUT Y
Answer: ____________________
Answer: ____________________________________________
____________________________________________________
____________________________________________________
10. Trace the Loop (10 Marks) Complete the trace table for the following algorithm:
Logic:
1. SET Total TO 0
2. SET Count TO 1
3. WHILE Count <= 3
4. SET Total TO Total + (Count * 2)
5. SET Count TO Count + 1
6. END WHILE
7. OUTPUT Total
1 1 YES 0 + (1*2) 2
2 2 YES 2 + (2*2) 6
4 4 NO - ____
1. Start.
2. Ask user: "Enter Sugar Level (0-3)".
3. Input Sugar.
4. Check: Is Sugar > 3?
• YES: OUTPUT "Too much sugar!" and go back to Step 2 (Input).
• NO: OUTPUT "Dispensing Coffee...".
5. Stop.