Flowchart Basics
Flowchart Basics
Non-Iterative Iterative
Formula/Value
Totaling Counting Extreme Values
Calculation
Non-Iterative Algorithm
(Simple Input-
In non-iterative algorithm we usually accept/input data to find/calculate some values either through some
formula or from simple calculation. Once calculation is done we release the results. In some questions your
Process_Output
calculation might be conditional, some time your output would be depending on some criteria but in any
case there won’t be any loop involved.
Write an algorithm in the form of a flowchart which takes temperatures input in Fahrenheit. Convert the
temperature in Celsius with the help of following formula:
Start of
Flowchart
Start
Here we decide the variable to be used and
initialized them. In this particular question
we have taken TempA for Temperature (in
TempAç0 Fahrenheit) and TempB for Temperature (in
TempBç0
Celsius)
Output
Command
Output
TempB
End of
Flowchart
End
Practice question:
Question 01:
Customers can withdraw cash from an Automatic Teller Machine (ATM).
• withdrawal is refused if amount entered > current balance
• withdrawal is refused if amount entered > daily limit
• if current balance < $100, then a charge of 2% is made
• if current balance $100, no charge is made
Write an algorithm which inputs a request for a sum of money, decides if a withdrawal can be
made and calculates any charges. Appropriate output messages should be included.
Input Amount
If Amount>Current Balance then Print “Withdrawal Refused”
If Amount>Daily Limit then Print “Withdrawal Refused”
Current Balance= Current Balance – Amount
If Current Balance<100 then Charges=Current Balance -2% Else Charges=0
Reason Variable Name Type Initial Value
Sum of Money Amount Number 0
Current Balance CB/Balance Number 0
Daily Limit DL/Limit/DailyLimit Number 0
Charges Ch/Charges Number 0
Question 02:
Regis lives in Brazil and often travels to USA, Europe and Japan. He wants to be able to convert
Brazilian Reais into US dollars, European euros and Japanese yen. The conversion formula is:
For example, if Regis is going to USA and wants to take 1000 Reais (and the exchange rate is 0.48)
then he would input USA, 1000 and 0.48 and the output would be: 480 US dollars.
Write an algorithm, using pseudocode, which inputs the country he is visiting, the exchange rate
and the amount in Brazilian Reais he is taking. The output will be value in foreign currency and the
name of the currency.
Question 03:
Daniel lives in Italy and travels to Mexico, India and New Zealand. The times differences are:
(b) Describe, with examples, two sets of test data you would use to test your algorithm.
Iterative Algorithm
(Simple Input-
In iterative algorithm you repeat one or more statement many times. Some time you know how many times
the process has to be repeated. This is so called count based loop/iteration i.e. calculate BMI of 30 students
Process_Output
or calculate tax of 5000 houses. But on many occasions you don’t know how many times you have to
repeat the process. In such cases repetition will be depending on some condition i.e. repeat while a certain
condition is True i.e. inputs a set of positive numbers (which end with -1) & outputs the value of the largest
(highest) number input. In this question you don’t know how many positive numbers are there rather you
have been given a condition i.e. enter -1 to stop or exit the loop.
Start Start
Numç0
Numç0 CountAç0
Countç0 Largestç0
CountAç0
Largest0ç0 Input
Num
Yes
Count=50
Yes Num= - 1
No
No
Input
Num
Yes Num>100 No
Yes No
Num>100
CountA ç CountA + 1
CountA ç CountA + 1
Yes Num>Largest No
Yes No
Num>Largest
Largest ç Num
Largest ç Num
Input
Num
Count ç Count + 1
End
End
Write an algorithm, using pseudocode or a flowchart, which Write an algorithm, using pseudocode or a flowchart, which
• inputs 50 positive numbers • inputs a set of positive numbers (which end with -1)
• outputs the average (mean) value of the input numbers • outputs the average (mean) value of the input numbers
• outputs the value of the largest (highest) number input • outputs the value of the largest (highest) number input
Start
Start
Numç0
Totalç0
Countç0 Countç0
Totalç0 Largest0ç0
Largest0ç0 Avgç0
Numç0
Avgç0
Input
Num
Yes
Count=50
Yes
No Num= - 1
No
Input
Num
TotalçTotal + Num
CountçCount + 1
Yes No
Num>Largest
Yes No
Num>Largest
Largest ç Num
Largest ç Num
Count ç Count + 1
Input
Num
Avg ç Total / 50
End
1) Start of
Start Flowchart
Countç0
CountAç0
CountBç0 2) Here we decide the variables to be used
TempAç0 and initialized them. All numerical variable
TempBç0
Totalç0
will be initialized with 0 except for lowest
Avgç0 that will be initialized with 1000.
Highestç0
Lowestç1000
11) Always
Calculate 3) Start of the loop. Set loop exit
Yes
Average outside is
condition i.e. Count=100 if you have
Count=100
loop. ? to input temperature over 100 days.
No 4) Input
AvgçTotal/100 Command
Input
TempA
5) Value
Output calculation if
Avg,
CountA, required.
TempBç (TempA-32)/1.8
CountB
Highest,
Lowest 6) Output result
only if point 5
Output exists.
13) End of TempB
End
Flowchart 7) Add the input value or result
of value calculated if average
Totalç Total +TempB has been asked to calculate
above. Lowestç
TempB
(c) average temperature of 100
days. 10) Increment the loop counter
by 1 for the next iteration and
(d) the highest and lowest go back to loop exit condition.
Countç Count+1
temperature recorded in these
100days.
1) Start of
Start Flowchart
Countç0
CountAç0
CountBç0 2) Here we decide the variables to be used
TempAç0 and initialized them. All numerical variable
TempBç0
Totalç0
will be initialized with 0 except for lowest
Avgç0 that will be initialized with 1000.
Highestç0
Lowestç1000
Dayç” “
3) Input
Input
Command
Day,
TempA
12) Always
Calculate 4) Start of the loop. Use input
Yes
Average outside Day= variable to set loop exit condition i.e.
loop. ”Friday”
? Day=”Friday” or Num=-1 etc.
No 5) Value
AvgçTotal/Count calculation if
required.
TempBç (TempA-32)/1.8
6) Output result
Output
Avg, only if point 5
CountA, Output exists.
CountB TempB
Highest,
Lowest
7) Add the input value or result
of value calculated if average
Totalç Total +TempB has been asked to calculate
14) End of End
Flowchart
8) Nothing to do with loop but
required for computing Average.
Countç Count+1
days.
11) Input command for next
(d) the highest and lowest Input
temperature recorded in these Day, iteration before returning to
100days. TempA loop,
Value Calculation
In many questions you will be asked to calculate some values with the help of any given formula or through
simple calculation. Sometime this calculation is quite simple (for example convert temperature from
Fahrenheit to Celsius) but on many occasions it will be conditional (calculate tax based on their house
value). In any case once you find the value you have to release the result. Don’t mix concept of totaling,
counting, average etc with value calculation.
Yes
is
Count=100
?
No
Input
TempA
TempBç (TempA-32)/1.8
Output
TempB
CountçCount+1
End
Value Calculation
Simple Calculation but Conditional Output:
Yes
is
Count=100
?
No
Input
TempA
TempBç (TempA-32)/1.8
Yes No
is
TempB>30
?
Output Output
TempB, “Hot TempB, “Normal
Summer Day” Temperature”
CountçCount+1
End
Value Calculation
Conditional Calculation with Simple Output:
Write an algorithm in the form of a flowchart which takes temperatures with scale input over a 100 day
period (once per day). Convert the temperature in Celsius if input temperature is in Fahrenheit with the help
of following formula: Temp (in Celsius)=(Temp (in Fahrenheit) - 32)/1.8
Start
Countç0
TempAç0
TempBç0
Yes is
Count=100
?
No
Input
TempA,
Scale
Yes is
No
Scale=
”Fahrenhei
t”
?
TempBç TempBç
(TempA+32)x1.8 (TempA-32)/1.8
Output
TempB
CountçCount+1
End
A town contains 5000 houses. Each house owner must pay tax based on the value of the house.
Houses over $200 000 pay 2% of their value in tax, houses over $100 000 pay 1.5% of their value in
tax and houses over $50 000 pay 1% of their value in tax. All others pay no tax. Write an algorithm
to solve this problem in the form of a flowchart.
Start
Countç0
HValueç0
Taxç0
Yes
Count=5000
No
Input HValue
Yes HValue>200 No
000
Tax ç (HValue * 2) /
100
Tax ç (HValue *
1.5) / 100
Tax ç (HValue * 1) /
100
Yes HValue<500 No
00
Tax ç 0
Print Tax
Count ç Count + 1
End
Practice Question:
Question 01:
A formula for calculating the body mass index (BMI) is:
Using pseudocode or otherwise, write an algorithm that will input the ID, weight (kg) and height
(m) of 30 students, calculate their body mass index (BMI) and output their ID, BMI and a comment
as follows:
A BMI greater than 25 will get the comment ‘OVER WEIGHT’, a BMI between 25 and 19 (inclusive)
will get ‘NORMAL’ and a BMI less than 19 will get ‘UNDER WEIGHT’.
Question 02:
Fuel economy for a car is found using the formula:
Write an algorithm, using pseudocode or otherwise, which inputs the Distance Travelled (km) and
the Fuel Used (litres) for 1000 cars. The Fuel Economy for each car is then calculated and
displayed.
Question 03:
The manufacturing cost of producing an item depends on its complexity. A company
manufactures three different types of item, with costs based on the following calculations:
Input
Temp
Yes No
is
Temp>=20
?
CountAçCountA+1 CountBçCountB+1
CountçCount+1
Output
CountA,
CountB
End
Counting:
This algorithm inputs 5 values and outputs how many input numbers were negative and how many
were positive
Start
Countç0
CountAç0
CountBç0
Yes
is
Count=5
?
No
Input
Num
Yes No
is
Num>0
?
CountAçCountA+1 CountBçCountB+1
CountçCount+1
Output
CountA,
CountB,
End
Practice Questions:
Question 01:
A company has 5000 CDs, DVDs, videos and books in stock. Each item has a unique 5-digit code
with the first digit identifying the type of item, i.e.
1 = CD
2 = DVD
3 = video
4 = book
For example, for the code 15642 the 1 identifies that it is a CD, and for the code 30055 the 3
identifies that it is a video.
Question 02:
5000 numbers are being input which should have either 1 digit (e.g. 5), 2 digits (e.g. 36), 3 digits
(e.g. 149) or 4 digits (e.g. 8567).
Write an algorithm, using pseudocode or flowchart only, which
• inputs 5000 numbers
• outputs how many numbers had 1 digit, 2 digits, 3 digits and 4 digits
• outputs the % of numbers input which were outside the range
Question 03:
A company is carrying out a survey by observing traffic at a road junction. Each time a car, bus,
lorry or other vehicle passed by the road junction it was noted down.
10 000 vehicles were counted during the survey.
Write an algorithm, using pseudocode, which:
• inputs all 10000 responses
• outputs the number of cars, buses and lorries that passed by the junction during the survey
• outputs the number of vehicles that weren’t cars, buses or lorries during the survey
Totaling
Totaling is usually done when you have to calculate average. In totaling we add the value entered by user
or derived from any calculation. Calculation of average and result of total and average will be placed
outside the loop. Never calculate average or show result of total or average inside the loop.
Yes
is
Count=100
?
No
Input
Temp
Total=Total+Temp
Yes No
is
Temp>=20
?
CountAçCountA+1 CountBçCountB+1
CountçCount+1
Output
CountA,
Avgç(Total/100) End
CountB,
Avg
Practice Questions:
Question 01:
A school is doing a check on the heights and weights of all its students. The school has 1000
students.
Write an algorithm, using pseudocode or a flowchart, which
• inputs the height and weight of all 1000 students
• outputs the average (mean) height and weight
• includes any necessary error traps for the input of height and weight
Question 02:
Write an algorithm, using pseudocode, which inputs rainfall (in cm) for 500 days and outputs the
average rainfall.
Question 03:
Write an algorithm, using pseudocode or otherwise, which inputs the Distance Travelled (km) and
the Fuel Used (litres) for 1000 cars. The Fuel Economy for each car is then calculated and the
following outputs produced:
• Fuel Economy for each car
• average (mean) Fuel Economy for all of the cars input
Extreme Values
On many occasion you will be asked to find highest or lowest values or both. We call it finding extreme
values i.e. maximum/minimum, highest/lowest, fastest/slowest etc. For example Write an algorithm in the
form of a flowchart which takes temperatures input over a 100 day period (once per day) and outputs the
highest and lowest temperature recorded in these 100days.
Note: We always initialize lowest value with 1000 instead of 0 and values of Highest/Lowest will never be
released within the loop.
Start
Countç0
Highç0
Lowç1000
Yes
is
Count=100
?
No
Input
Temp
Yes No
is
Temp>High
HighçTemp
Yes No
is
Temp<Low
LowçTemp
CountçCount+1
Output
High,
Low
End
Practice Questions:
Question 01:
A car’s speed is measured between points A and B, which are 200 km apart.
What is the final speed of a car if it takes 2 hours to get from A to B? [1]
(b) Write an algorithm, using pseudocode or otherwise, which inputs the times for 500 cars,
calculates the final speed of each car using the formula in part (a), and then outputs:
• the final speed for ALL 500 cars
• the slowest (lowest) final speed
• the fastest (highest) final speed
Question 02:
Write an algorithm, using pseudocode or flowchart only, which:
• inputs three numbers
• outputs the largest of the three numbers
Question 03:
As part of an experiment, a school measured the heights (in metres) of all its 500 students.
Write an algorithm, using pseudocode, which inputs the heights of all 500 students and outputs the
height of the tallest person and the shortest person in the school.