From 0032b79a49c96797ef133aa687231c87c3969398 Mon Sep 17 00:00:00 2001 From: "louis.germain" Date: Sat, 4 Nov 2023 18:21:01 +0100 Subject: [PATCH] =?UTF-8?q?modification=20de=20la=20fonction=20du=20d?= =?UTF-8?q?=C3=A9passement=20des=20contraintes=20pour=20correspondre=20au?= =?UTF-8?q?=20fctment=20du=20panier?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.h | 2 +- src/panier.c | 73 +++++++++++++++++++++++++++------------------------- 2 files changed, 39 insertions(+), 36 deletions(-) diff --git a/src/main.h b/src/main.h index e5feada..f4c767f 100644 --- a/src/main.h +++ b/src/main.h @@ -40,7 +40,7 @@ int recherche(int val, int tab[], int tlog); //! PANIER 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 *cagnotte, float tabWeight[], float tabVolume[], float tabPrice[], int tabItemRef[], int tabBasketRef[], int tabBasketQuantity[], int tlogItem, int tlogBasket) int basket_add (int tab_reference[], float weight[], float volume[], float unitPrice[], float *cagnotte, int basket_tab_ref[], int basket_tab_qte[],int tlog, int tlog_basket); void display_basket(int basket_tab_ref[], int basket_qte[], float weight[], float volume[], float unitPrice[], float *cagnotte,float weight_constraint, float volume_constraint, int tlog, int tlog_basket); int reinit_basket(int tlog_basket); diff --git a/src/panier.c b/src/panier.c index fd7a01c..2a5c0f6 100644 --- a/src/panier.c +++ b/src/panier.c @@ -51,52 +51,55 @@ void clientConstraint(float *weight, float *volume, float *price) * @return an integer value. */ // TODO réécrire cette documentation -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 *cagnotte, float tabWeight[], float tabVolume[], float tabPrice[], int tabItemRef[], int tabBasketRef[], int tabBasketQuantity[], int tlogItem, int tlogBasket) { + int index, found, i; float totalWeight = 0, totalVolume = 0, totalPrice = 0, cagnotteUse; - int i; - for (i=0; i weightConstraint) - { - printf("Attention, la contrainte de charge maximale du véhicule a été dépassée de %.2f, veuillez retirer un article\n", totalWeight - weightConstraint); - return -1; - } - if (totalVolume > volumeConstraint) + index = searchTab(tabItemRef, tabBasketRef[i], tlogItem, &found); + if (found == 1) { - printf("Attention, la contrainte de volume maximum a été dépassé de %.2f, veuillez retirer un article\n", totalVolume - volumeConstraint); - return -1; - } - if (*priceConstraint != -1 && totalPrice > *priceConstraint) - { - printf("Attention, la contrainte de budget maximum a été dépassé de %.2f\n", totalPrice - *priceConstraint); - if (*cagnotte < totalPrice) + totalWeight += tabWeight[index] * tabBasketQuantity[i]; + totalVolume += tabVolume[index] * tabBasketQuantity[i]; + if (*priceConstraint != -1) + totalPrice += tabPrice[index] * tabBasketQuantity[i]; + if (totalWeight > weightConstraint) { - printf("Le prix total excédant votre cagnotte, veuillez retirer un article\n"); + printf("Attention, la contrainte de charge maximale du véhicule a été dépassée de %.2f, veuillez retirer un article\n", totalWeight - weightConstraint); return -1; } - else + if (totalVolume > volumeConstraint) { - 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); - if (cagnotteUse == -1) - return -1; - while (cagnotteUse > *cagnotte || totalPrice-cagnotteUse > *priceConstraint) + printf("Attention, la contrainte de volume maximum a été dépassé de %.2f, veuillez retirer un article\n", totalVolume - volumeConstraint); + return -1; + } + if (*priceConstraint != -1 && totalPrice > *priceConstraint) + { + printf("Attention, la contrainte de budget maximum a été dépassé de %.2f\n", totalPrice - *priceConstraint); + if (*cagnotte < totalPrice) { - 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: "); - 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("Le prix total excédant votre cagnotte, veuillez retirer un article\n"); + return -1; + } + 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); scanf("%f", &cagnotteUse); if (cagnotteUse == -1) - return -1; - *cagnotte -= cagnotteUse; - *priceConstraint += cagnotteUse; + return -1; + while (cagnotteUse > *cagnotte || totalPrice-cagnotteUse > *priceConstraint) + { + 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: "); + 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); + scanf("%f", &cagnotteUse); + if (cagnotteUse == -1) + return -1; + *cagnotte -= cagnotteUse; + *priceConstraint += cagnotteUse; + } } } }