Ok, I looked up sorting and found qsort. I also been playing around
here is what i have
#include
#include
#include
struct RECORD {
char name[20];
int num1, num2, num3;
};
int compareProduct (RECORD *rec1, RECORD *rec2)
{ return (rec1->num1 * rec1->num2) - (rec2->num1 * rec2->num2);
}
void main(void)
{
RECORD values[11] =
{ { "Brian Devaux ",53000, 5, 1 },
{ "Amanda Trapp ",89000, 3, 2 },
{ "Baclan Nguyen ",93000, 3, 3 },
{ "Sarah Gilley ",17000, 1, 4 },
{ "Warren Rexroad ",72000, 7, 5 },
{ "Jorge Gonzales ",65000, 2, 6 },
{ "Paula Hung ",34000, 3, 7 },
{ "Lou Mason ",21000, 6, 8 },
{ "Steve Chu ",42000, 4, 9 },
{ "Dave Lightfoot ",63000, 3, 10},
{ "Joanna Brown ",33000, 2, 11},
};
int i;
/* Show the original order of the records */
for (i=0; i < 11; i++)
printf ("%10s %3d %3d %3d\n",
values[i].name,values[i].num1,values[i].num2, values[i].num3);
/* now sort them based on the max product of the nums */
qsort (values,11,sizeof(RECORD),
(int (*)(const void *,const void *)) compareProduct);
/* Show the records after they're sorted */
printf ("\n\n");
for (i=0; i < 11; i++)
printf ("%10s %3d %3d %3d %4d\n",
values[i].name,values[i].num1,values[i].num2,values[i].num3,
(values[i].num1/1000) + (values[i].num2 - values [i].num3));
}
now im missing something, for some odd reason my numbers start to sort, then they dont. any help?