“Wind was less than 12 knots so Mary could safely land in Courtenay, but the wind conditions delayed their leave time and has slowed down their travel so that their overall travel time is longer than expected. Mary will not make her booked landing time. Write an algorithm that will determine if there is a later landing time available in the Courtenay airfield. If not, she will have to default to Smits Field”.
- Input how long the trip will take – store it in a variable called “tripLength”
- Input when Mary and Louise took off – store it in a variable called “leaveTime”.
- Calculate arrival time by adding “tripLength” + “leaveTime”.
- Input the landing times in Courtenay, store it in a variable called “landTimes”.
- Compare “arrivalTime” to each number sequence in “landTimes”.
- If “arrivalTime” is greater than “landTimes” – move to the next available “landTimes”.
- If “arrivalTime” is less than or equal to “landTimes”, Mary can land in Courtenay as output “landDestination: Courtenay”.
- If “arrivalTime” remains greater than “landTimes”, Mary must default to “landDestination: Smit Airfield”.
mwilson
The inputs for this one would be ‘current time’ and ‘remaining trip time’ – because the calculations are being done while in the air (so leave time isn’t relevant).
Otherwise, this works.