Question: Write a program that adds two time periods. Both time periods are expressed in hours, minutes and seconds and the resulting sum should also be
Write a program that adds two time periods. Both time periods are expressed in hours, minutes and seconds and the resulting sum should also be expressed in hours, minutes and seconds.
Given the following initial values:
hours1 = 5 minutes1 = 32 seconds1 = 43 hours2 = 6 minutes2 = 45 seconds2 = 29
the program should produce the following output:
5 hours 32 minutes and 43 seconds added to 6 hours 45 minutes and 29 seconds is equal to 12 hours 18 minutes and 12 seconds
Please note the following:
- Do not include the above variable initialization statements in your code. They will be provided for you with each CodeRunner test case.
- You can assume all 6 variables will always be assigned integer values.
- You need to use the modulus (%) and floor division (//) operators in your calculations.
For example:
| Test | Result |
|---|---|
hours1 = 5 minutes1 = 32 seconds1 = 43 hours2 = 6 minutes2 = 45 seconds2 = 29 | 5 hours 32 minutes and 43 seconds added to 6 hours 45 minutes and 29 seconds is equal to 12 hours 18 minutes and 12 seconds |
hours1 = 13 minutes1 = 41 seconds1 = 6 hours2 = 8 minutes2 = 57 seconds2 = 4 | 13 hours 41 minutes and 6 seconds added to 8 hours 57 minutes and 4 seconds is equal to 22 hours 38 minutes and 10 seconds |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
