First, let me show my code.
void findRev(Items* products[], int numOfProd) {
for (int i = 0; i < (numOfProd - 1); i++) {
double rev1 = products[i]->price * products[i]->numSold;
double rev2 = products[i + 1]->price * products[i + 1]->numSold;
if (rev1 > rev2) {
Items* temp = products[i];
Items* temp2 = products[i + 1];
temp2 = products[i];
temp = products[i + 1];
}
}
}
I have a struct
of different items. I'm trying to sort them by revenue, but I have to find the revenue first.
I know I can just add a revenue field to my struct, but my professor said we're not allowed to do that.
I wrote this function but it doesn't work the way i wanted it to. I have used bubble sort and selection sort before. I just cant seem to figure out how to use one of them for this instance. I have looked all through my books and online. And my professor it would be good to find the revenue within the sorting loop. I just can't figure out how. Anyway i can make it work?