You are on page 1of 2

Pseudocode practice for Loop

1. Write pseudo code to print all multiples of 5 between 1 and 100 (including both 1 and 100)

2. Tickets are sold for a concert at $20 each. If 10 tickets are bought then the discount is 10%; if 20
tickets are bought the discount is 20%. No more than 25 tickets can be bought in a single
transaction.
a. Use pseudocode to write an algorithm to calculate the cost of buying a given number
of tickets.
b. Explain how you would test your algorithm.

3. A school with 600 students wants to produce some information from the results of the four
standard tests in Maths, Science, English, and, IT. Each test is out of 100 marks. The
information output should be the highest, lowest and average mark for each test and the highest,
lowest and average mark overall. All the marks need to be input.
a. Use pseudocode to write an algorithm to complete this task.
b. Explain how you would test your algorithm.
c. Identify the changes you would need to make to the algorithm to reduce the number of
students to 5 and the number of subjects to 2.
d. Identify the test data needed to test with the reduced number of students and subjects.
e. With the set of data, you have chosen, set up and complete a trace table so that you can
compare your expected results with the actual results when you dry run the algorithm.

4. Show three ways a loop to add up five numbers and print out the total can be set up using
pseudocode.

5. Explain which loop is the most efficient to use.

6. A sweet shop sells 500 different sorts of sweets. Each sort of sweet is identified by a unique four-
digit code. All sweets that start with a one (1) are chocolates, all sweets that start with a two (2)
are toffees, all sweets that start with a three (3) are jellies and all other sweets are miscellaneous
and can start with any other digit except zero.
a. Write an algorithm, using a flowchart, which inputs the four-digit code for all 500 items
and outputs the number of chocolates, toffees, and, jellies.
b. Explain how you would test your flowchart.
c. Decide the test data to use and complete a trace table showing a dry run of your
flowchart.

7. The temperature in an apartment must be kept between 18°C and 20°C. If the temperature
reaches 22°C then the fan is switched on; if the temperature reaches 16°C then the heater is
switched on, otherwise, the fan and the heaters are switched off.
The following library routines are available:
 GetTemperature  HeaterOn
 FanOn  HeaterOff
 FanOff
Write an algorithm, using pseudocode or a flowchart, to keep the temperature at the right
level.
8. Daniel lives in Italy and travels to Mexico, India, and New Zealand. The time differences are:
Thus, if it is 10:15 in Italy it will be 14:45 in India.
a. Write an algorithm, using pseudocode or otherwise, which:
 inputs the name of the country
 inputs the time in Italy in hours (H) and minutes (M)
 calculates the time in the country input using the data from the table
 outputs the country and the time in hours and minutes.
b. Describe, with examples, two sets of test data you would use to test your algorithm.

9. 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.

10. A small café sells five types of items:


 bun 0.50 dollars  sandwich 2.10 dollars
 coffee 1.20 dollars  dessert 4.00 dollars
 cake 1.50 dollars
Write an algorithm, using pseudocode or a program flowchart only, which
 inputs every item sold during the day
 uses an item called ‘end’ to finish the day’s input
 adds up the daily amount taken for each type of item
 outputs the total takings (for all items added together) at the end of the day
 outputs the type of item that had the highest takings at the end of the day.

11. 5000 numbers are being input which should have either one digit (e.g. 5), two digits (e.g. 36),
three digits (e.g. 149), or four digits (e.g. 8567). Write an algorithm, using pseudocode or a
flowchart only, which inputs 5000 numbers
 outputs how many numbers had one digit, two digits, three digits, and four digits .
 outputs the percentage of numbers that were outside the range.

12. Create an algorithm to calculate the cost of sending a parcel using the following rules:
 If the weight of the parcel is 2 kg or under then the standard charge is $3.
 There is then a charge of $2 for each extra kilogram up to 10 kg.
 After 10 kg the charge per extra kilogram is $3.
 Display the cost of the parcel
Provide two versions of the algorithm. One should use a pre-condition loop and the other a post-
condition loop

You might also like