I'm trying to convert in hours and minutes starting from times (recorded in an array) in minutes from midnight. But I see that there is a rounding error. For example, the departure time 583 (minutes from midnight), calculating the time and minutes like this:
583/60 = 9.716666
I take the whole part (9) hours. Then I take the decimal part and do this:
0.716666 * 60 = 42.99996
The minutes would be 43 but unfortunately I can not extrapolate this value rounding it up.
Some idea?
#include <stdio.h>
#define SIZE (int)sizeof(departures) / sizeof(departures[0])
int main(void) {
int hours, minutes, mmin, fh, fm;
float res;
int departures[] = {480, 583, 679, 767, 840, 945, 1140, 1305};
int Arrivals[] = {616, 712, 91, 900, 968, 1075, 1280, 1438};
for(int i = 0; i < SIZE; i++) {
res = (float)departures[i] / 60;
fh = departures[i] / 60;
fm = ((float)departures[i] / 60 - fh) * 60;
printf("%d) %d:%d (%f)\n", i, fh, fm, res);
}
return 0;
}