Click here to Skip to main content
15,747,637 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
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;

int main()

   stsales sales[1000];
   int countsales=0;


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

Any help!!!!
[no name] 6-Jul-15 12:55pm    
Any help.... with what? If you do not understand your homework assignment you should be asking your teacher.
Sergey Alexandrovich Kryukov 6-Jul-15 13:20pm    
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?


1 solution

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....
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900