14,239,281 members
Rate this:
See more:
I have a struct to store sales data. And i want to make a function to find the max and min value of a float variable (final_price) that is inside stsales struct.

My struct:

```typedef struct{
int idcustomersale;
char serialnumberproductsale[10]
float final_price;
}stsales;

int main()
{

stsales sales[1000];
int countsales=0;

}

//Code of function find_min_max...........```

Any help!!!!
Posted

Any help.... with what? If you do not understand your homework assignment you should be asking your teacher.

The question, as formulated, makes no sense. The concept of "maximum" and "minimum" is only defined for some set, and not for every set, but only for the set on which the order relationship is defined. Still, not all such sets have minimum and maximum, but if the set if finite, both minimum and maximum can be found; and all sets represented in computers are finite.

Now, if you mean not "in a variable of a struct", but mean some set of instances of this type, where the order is defined by arithmetic >= order of the final_price instance member, it makes the problem correct, but also trivial. You simply need to compare those values in some loop. What have you tried so far?

—SA

Rate this:

Solution 1

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!

If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!

This isn't difficult - all you need to do is set up a max and min value, then loop though each of the values in your array checking each against both. If you find a smaller-than-minimum value, set it to the one one. Similarly for the maximum. After the loop, you have the max and min values
Hint: You can set the initial value of both maximum and minimum to the same value if you think about it, but it won't be the same for each time you execute your program....