Correction de bugs

doc
louis.germain 2 years ago
parent b8f716d3ed
commit 658e1d2469

@ -38,4 +38,4 @@ int recherche(int val, int tab[], int tlog);
//! PANIER //! PANIER
void clientConstraint(float *weight, float *volume, float *price); void clientConstraint(float *weight, float *volume, float *price);
int constraintExceeded(float weightConstraint, float volumeConstraint, float priceConstraint, float tabWeight, float tabVolume, float tabUnitPrice, int tabQuantity, int tlog, float *cagnotte); int constraintExceeded(float weightConstraint, float volumeConstraint, float *priceConstraint, float tabWeight[], float tabVolume[], float tabUnitPrice[], int tabQuantity[], int tlog, float *cagnotte);

@ -30,16 +30,16 @@ void clientConstraint(float *weight, float *volume, float *price)
} }
} }
int constraintExceeded(float weightConstraint, float volumeConstraint, float priceConstraint, float tabWeight, float tabVolume, float tabUnitPrice, int tabQuantity, int tlog, float *cagnotte) int constraintExceeded(float weightConstraint, float volumeConstraint, float *priceConstraint, float tabWeight[], float tabVolume[], float tabUnitPrice[], int tabQuantity[], int tlog, float *cagnotte)
{ {
float totalWeight = 0, totalVolume = 0, totalPrice = 0, cagnotteUse; float totalWeight = 0, totalVolume = 0, totalPrice = 0, cagnotteUse;
int i; int i;
for (i=0; i<tlog; i++) for (i=0; i<tlog; i++)
{ {
totalWeight += tabWeight[i]; totalWeight += tabWeight[i] * tabQuantity[i];
totalVolume += tabVolume[i]; totalVolume += tabVolume[i] * tabQuantity[i];
if (priceConstraint != -1) if (*priceConstraint != -1)
totalPrice += tabUnitPrice[i]; totalPrice += tabUnitPrice[i] * tabQuantity[i];
if (totalWeight > weightConstraint) if (totalWeight > weightConstraint)
{ {
@ -51,34 +51,34 @@ int constraintExceeded(float weightConstraint, float volumeConstraint, float pri
printf("Attention, la contrainte de volume maximum a été dépassé de %.2f, veuillez retirer un article\n", totalVolume - volumeConstraint); printf("Attention, la contrainte de volume maximum a été dépassé de %.2f, veuillez retirer un article\n", totalVolume - volumeConstraint);
return -1; return -1;
} }
if (priceConstraint != -1 && totalPrice > priceConstraint) if (*priceConstraint != -1 && totalPrice > *priceConstraint)
{ {
printf("Attention, la contrainte de budget maximum a été dépassé de %.2f\n", totalPrice - priceConstraint); printf("Attention, la contrainte de budget maximum a été dépassé de %.2f\n", totalPrice - *priceConstraint);
if (cagnotte < totalPrice) if (*cagnotte < totalPrice)
{ {
printf("Le prix total excédant votre cagnotte, veuillez retirer un article\n"); printf("Le prix total excédant votre cagnotte, veuillez retirer un article\n");
return -1; return -1;
} }
else else
{ {
printf("Vous pouvez utiliser votre cagnotte, dont le montant est de %.2f, entrez le montant à utiliser ou -1 si vous voulez retirer un article: ", cagnotte); printf("Vous pouvez utiliser votre cagnotte, dont le montant est de %.2f, entrez le montant à utiliser ou -1 si vous voulez retirer un article: ", *cagnotte);
scanf(%f, &cagnotteUse); scanf("%f", &cagnotteUse);
if (cagnotteUse == -1) if (cagnotteUse == -1)
return -1; return -1;
while (cagnotteUse > cagnotte || totalPrice-cagnotteUse < priceConstraint) while (cagnotteUse > *cagnotte || totalPrice-cagnotteUse > *priceConstraint)
{ {
if (cagnotteUse > cagnotte) if (cagnotteUse > *cagnotte)
printf("Erreur: vous ne pouvez pas utiliser plus que vous n'avez, réessayez ou entrer -1 si vous souhaitez retirer un article: "); printf("Erreur: vous ne pouvez pas utiliser plus que vous n'avez, réessayez ou entrer -1 si vous souhaitez retirer un article: ");
if (totalPrice-cagnotteUse < priceConstraint) if (totalPrice-cagnotteUse > *priceConstraint)
printf("Erreur: vous n'avez pas utilisé assez de votre cagnotte, vous devez utiliser au moins %.2f, veuillez rentrer le montant à utiliser ou -1 si vous voulez retirer un article: ", totalPrice - priceConstraint); printf("Erreur: vous n'avez pas utilisé assez de votre cagnotte, vous devez utiliser au moins %.2f, veuillez rentrer le montant à utiliser ou -1 si vous voulez retirer un article: ", totalPrice - *priceConstraint);
scanf("%f", &cagnotteUse); scanf("%f", &cagnotteUse);
if (cagnotteUse == -1) if (cagnotteUse == -1)
return -1; return -1;
*cagnotte -= cagnotteUse; *cagnotte -= cagnotteUse;
priceConstraint += cagnotteUse; *priceConstraint += cagnotteUse;
} }
} }
} }
} }
return 0 return 0;
} }
Loading…
Cancel
Save