You want to find out which fraction of your car’s use is for commuting to work,
and which is for personal use. You know the one-way distance from your home to work. For a particular period, you recorded the beginning and ending mileage on the odometer and the number of work days. Write an algorithm to settle this question.
Initial a particular period (days) N
Initial the number of working days
Initial the beginning mileage
Initial the ending mileage
Initial one-way distance from home to work
Initial the fraction of driving the car for work
If a particular period of days is less than the number of working days
Rise an error or exception
Else
The fraction of driving the car for work = 2 * one-way distance from home to work / (the ending mileage – the beginning mileage)