# stupid c question re arrays

• 04-10-2002
C. Unger
stupid c question re arrays
Okay, this is a basic stupid easy question on a homework problem that I have not been able to figure out, and I would really appreciate a hint.

Overview, I am creating a traffic report where the user enters the traffic volume recorded for each hour for several hours. Then various information is displayed/calculated using this information (average, median, etc).

I have two single dimensional arrays, one with the hours and one with the user input for the traffic volumes.

I need to show a volume and the hour it was recorded for various data manipulations (smallest number, largest, sort in ascending order, etc) How do I return both the hour and the volume in my function?

The following code finds the smallest volume, but I can't get it to show the lowest hour. The code below will only give the last hour, for the last x, because of the for loop structure.

I tried originally to return these as int values, but I ended up with gibberish, so I switched to a void returning a printf statement. Do I need to use pointers? A nested for loop? Go back to returning int values for hour and volume from the function?

void smallest(int hour[], int volume[], int time, int cars)
{
int x, y, lowhour, lowestvol = 1000;

for (x = 0; x < cars; x++)
{if (volume[x] < lowestvol)
lowestvol = volume[x];
lowhour = hour[x]
}
}
printf("The lowest traffic volume was %d recorded at %d.\n", lowestvol, lowhour);

}

Thanks,
C.Unger
• 04-10-2002
quzah
Quote:

I need to show a volume and the hour it was recorded for various data manipulations (smallest number, largest, sort in ascending order, etc) How do I return both the hour and the volume in my function?
You could make a structure:
Code:

```struct Data { int hour; int volume; }; Data smallest( ... ) {     struct Data d = { -1, -1 };     ... do stuff ...     d.hour = hour;     d.volume = volume;     return d; }```
Quzah.