Just wanted to know if this function’s results will always hold?
private int calcHourDiff(int start, int end) {
int diff;
if(start > end) {
diff = ((2400 - start) + end) / 100;
} else if(start < end) {
diff = (end - start) / 100;
} else {
diff = 0;
}
return diff;
}
Functions are passed in as military time and it should return the amount of hours in between. Passed in values will always be “easy” numbers such as 1200, 1400, 2100 not 2134 or 015. It needs to be able to properly calculate all possible cases, will this function hold?
I had trouble for values ranging from the night (8PM or 2000) to the next day (6AM or 600) and I think this should fix it?
Thanks for the time.
Just to be different, here’s a version without any conditionals at all: