I am writing a C program to take in a value representing a time of the day in 24 hour format, and a time duration in similar format, positive or negative. This program should calculate the 24 hour time after the duration (that is, beginning + duration = end). For example, 1345 and 345 would output 1730.
However, I have no idea how to handle improper inputs. For example, values like 2372 or 2520 shouldn’t be accepted. As well, if I have (for example) 100 and -200, I should get 2300 as output instead of -100. In short, I know that the first two numbers should be mod 24, and the last two numbers should be mod 60, but I don’t know how to apply these operations to the input. Can anyone offer any tips on how I can do this?
Read the input as an
int, separate the minutes from the hours and check both of them: