Ok, I'm starting to understand this now, at least I think I am. I calculated each slot in the array to determine the smallest difference, but got a negative number. Now, I'm trying to use the abs() function, it's not working. The error message I get is "too few arguments to function 'abs'." How do I fix this problem?
Code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int departure_times[] =
{8*60, 9*60+43, 11*60+19, 12*60+47,
14*60, 15*60+45, 19*60, 21*60+45};
// going to use this array later
// int arrival_times[] =
// { 10*60+16, 11*60+52, 13*60+31, 15*60,
// 16*60+8, 17*60+55, 21*60+20, 23*60+58};
int i, hours, minutes, small;
int length = sizeof(departure_times) / sizeof(departure_times[0]);
printf("Enter a 24-hour time: ");
scanf("%d:%d", &hours, &minutes);
printf("You entered %d:%d\n", hours, minutes);
for (i = 0; i < length; i++)
{
hours = hours * 60;
minutes = minutes + hours;
departure_times[i] -= minutes;
for (small = departure_times[0], i =1; i < length; ++i)
{
if (departure_times[i] < small)
{
small = departure_times[i];
}
}
printf("Minutes: %d\n", small); //going to be erased later
}
getchar();
getchar();
return 0;
}