Skip to main content

Example Loop Program

A car hire company calculates the charge for car hire with a standard rate for each mile travelled at 20p a mile, along with a 'wear and tear' surcharge of 25 for each complete 1000 miles travelled. Write a program to accept as input the mileometer readings at the start and finish of a hire and calculate the total charge for the hire.

Develop an algorithm for a program that will repeatedly accept as input the mileometer readings at the start and finish of a hire. The user will finish by typing in a zero for the start miles.

Data Input(s)

StartMiles - Integer
StopMiles - Integer

Data Output(s)

TotalCharge - Real

Data Processes (Using Sample Inputs)

StartMiles = 1000 StopMiles = 1500

TotalMiles = StopMiles - StartMiles
TotalMiles = 1500 - 1000
TotalMiles = 500

StandardCharge = TotalMiles * 20p
StandardCharge = 500 * 0.20
StandardCharge = 100

Surcharge = (TotalMiles DIV 1000) * 25
Surcharge = (500 DIV 1000) * 25
Surcharge = 0

TotalCharge = StandardCharge + Surcharge
TotalCharge = 100 + 0
TotalCharge = 100

Next: Data Table for Loop Program