82.0k views
1 vote
c Write a program that reads two times in military format (0900, 1730) and prints the number of hours and minutes between the two times. Make sure the result is positive.

User Rasel
by
6.2k points

1 Answer

3 votes

Answer:

# This program was written in Python language as my choice language

# as the user did not indicate the particular language to be used for the #question

# Request inputs from the user.

time_1 = int(input("Please enter the first time: "))

time_2 = int(input("Please enter the second time: "))

# The following if statement ensures the result is positive

if time_2 < time_1 :

time_2 = time_2 + 2360

# Compute the hours and minutes in the difference.

difference = time_2 - time_1

hours = difference // 100

minutes = difference % 100

# The following two statements corrects any difference where the minutes value exceeds 60.

hours = hours + minutes // 60

minutes = minutes % 60

# Display the result.

print(hours, "hours", minutes, "minutes")

User GoldenJam
by
6.2k points