El chavo del ocho (the 'kid' pictured above) is a very poor boy who lives somewhere in Mexico city. He has always dreamed of going to Acapulco, a popular beach resort in the state of Guerrero on the Pacific coast of Mexico, located 377.6 Km away from where el chavo lives. His neighbor Don Ramon, who is also poor, has the rare opportunity to borrow a rather old car and offers to take el chavo to Acapulco with him.

Alas! Disaster strikes along the way and the car breaks down. Since they are already on their way and far from where they live, they decide to continue the journey on foot! El chavo takes note of the distance traveled so far and wants to know exactly how long it is going to take them to get to Acapulco if they travel at a speed of 5 Km/h. Unfortunately, neither el chavo nor don Ramon are good with math and they have no idea how long the journey will take. The only thing they managed to do is look at each other and say: "Y ahora, ¿quién podrá ayudarnos?" (who can help us now?).

Your assignment

You are to play the role of el chapulín colorado (the red grasshopper), a superhero that appears whenever the phrase "Y ahora, ¿quién podrá ayudarnos?" is said out loud.

Write a program that solves el chavo's dilemma. Assume that the user will input the distance traveled (in Km) at the moment the car broke down. The program should then display the remaining distance (in Km) and tell the user how long will it take to get to the destination. The program should report the time in days, hours, minutes and it should round to the nearest second. Here is an example of how the program should behave if the user enters 100.3 kilometers

Your program should use the maximum amount of the largest unit of time, starting with days and so on. In the example above, the output " 0 days, 0 hours, 0 minutes and about 199656 seconds" would not be acceptable.

You may assume:

  • The user will input a decimal between 0 and 377.6 with at most 3 decimals. E.g. The user could enter 377 or 234.008 or 32.5; but it will not enter -23 nor 380 nor 100.1234

The following information might come in handy:

  • time = distance / speed
  • 5 Km/h = 5000 m/h = 1.38889 m/s
  • 1 Km = 1000 m
  • 1 day = 24 h = 1440 min = 86400 s
  • 1 h = 60 min = 3600 s
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.