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. Anyway i can make it work?
Aucun commentaire:
Enregistrer un commentaire