Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Beckie

macrumors newbie
Original poster
Apr 6, 2005
12
0
for some reason, I cannot get my function for finding the smallest number to work. I have one almost identical to this for finding the largest number and it works perfectly, and so I just switched from < to > and it isn't working. It's really strange. If you could help me out on this, I would greatly appreciate it.

Thank you so much!!
Take care,
Beckie

{
int row;
int col;
int smallest;
find smallest in each array of list

for (row = 0; row < 20; row++)
{
smallest = list[row].games[0];

for (col = 1; col < 15; col++)

if (smallest > list[row].games[col])
{
list[row].games[col] = smallest;
}
list[row].findlow = smallest;
col = 0;
}
 
Beckie said:
if (smallest > list[row].games[col])
{
list[row].games[col] = smallest;
}

Shouldn't this assignment be the other way around? Try this instead:

Code:
if (smallest > list[row].games[col])
{
   smallest = list[row].games[col];
}
 
Hi
Thanks for helping.

I tried that too before and it doesn't work. It puts everything at zero.

It's really strange.

Well anyway, thanks for helping!

Take care,
Beckie
 
I tried it and it worked perfectly for me after making the above change. Perhaps there's a bug somewhere else in your code, such as where you set the values in the arrays.
 
Thanks again HexMonkey for helping me with my program. You're the best!!!

Just in case someone needs to know how to do this in a program, the thing that was wrong with my find the smallest thing was that I had zeros in my array and I needed to change list[row].games[col] = smallest; to smallest = list[row].games[col]; so it was finding the zeros as being the smallest, logically so. So anyway, I had to make some adjustments and it works now.

So if anyone wants to use that, it works. :)

Take care,
Beckie
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.