Compare the minute portion of the leaving and entering time. If the first one is smaller than the second, Add 60 to the minute portion of the leaving time. Subtract 1 from the hour portion of the leaving time. Subtract the hour portions. Subtract the minute portions
minutesEnter = enter % 60; hoursEnter = enter / 60;
minutesExit = exit + 60; hoursExit = exit - 1;
Basically, what you had in mind and what the computers is 'thinking' is totally different. When we read time in 24-hours format (ie 1645) we know it means 4.45pm. But the computer only take it as a normal number (one thousand six hundred forty five).
Bare ONE thing in mind. This is normal MATHEMATICS for the computer and not TIME!
So, what you should do is very simple.
Compare the minutes of both times by using modulus 100.
If exit minute is smaller than entry, add 60 to exit time and minus 100 also to exit time. Then you minus them like a normal math sum.
Else, you just minus them like any other normal math sum.
Take example enter time is 1645 while exit time is 1715.
Why I use modulus is that I only want the minutes and not the hours.
So, when I modulus 1645 with 100 I get 16 extra 45. Right?
And moduls 1715 with 100 I get 17 extra 15. Right?
Then I compare 15 and 45. (obviously 45 is bigger)
So, I add 60 to exit. (1715+60=1775)
Then, minus 100 (as in minus 1 hour) from from exit. (1775-100=1675)
So, now exit holds the value of 1675 while enter is still 1645.
Finally, you minus 1675 and 1615 to get 30!
HOWEVER, since you enter 1645 BUT you want a display 16:45 right?
You'll need to have 2 variables. One to hold the modulus 100 result (which would be the minutesEnter / minutesExit) and another to hold the sum of enter/exit divided by 100 (which would be the hoursEnter / hoursExit).
Hope this helps. Good luck!