i have to intup the time periods(12 55; 18 00 etc) and distance from the console for a few journeys and then i have to output the journey with the greatest speed, how do i calculate the speed, is there a function for it?
i know how to calculate the speed, thanks. i mean if my time of journey looks like "505", how do i correctly calculate the speed without errors?
here's a part of my code that calculates the difference between two time periods i intup
What does '505' represent? What's the format/type of the departure/arrival times? Are the departure/arrival times always within the same 24 hour period?
505 is 5 hours and 5 minutes time difference. i've already found a way to calculate the difference between two time periods, but am stuck on the spead. but i'm gessing i need to find speed in km/minute first and then *60, right?
As others have mentioned, you need to convert the hours/minutes values into decimal minutes, or hours, or seconds. Write a function that does this conversion.
One other thing to consider, what about this trip:
start time: 23:18
end time: 02:23
In this case, the trip ends the following day. To handle this case, after you convert to a decimal value, check if the end time is "before" the start time. If so then add 24 hours to the end time.
Conceptually, you're computing the elapsed time from the start of the day on which the trip began. In other words, from 00:00 on the starting day.