From b8f716d3edc6c44dbed09676a62e6e9061c0572a Mon Sep 17 00:00:00 2001 From: "louis.germain" Date: Sun, 22 Oct 2023 20:27:22 +0200 Subject: [PATCH] =?UTF-8?q?ajout=20de=20l'alerte=20lorsque=20contrainte=20?= =?UTF-8?q?d=C3=A9pass=C3=A9e=20et=20de=20l'utilisation=20de=20la=20cagnot?= =?UTF-8?q?te?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.h | 3 ++- src/panier.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/src/main.h b/src/main.h index 47cbfb3..7478548 100644 --- a/src/main.h +++ b/src/main.h @@ -37,4 +37,5 @@ void displayClientList(int clientID[], float cagnotte[], int suspended[], int tl int recherche(int val, int tab[], int tlog); //! PANIER -void clientConstraint(float *weight, float *volume, float *price); \ No newline at end of file +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); \ No newline at end of file diff --git a/src/panier.c b/src/panier.c index ff52dca..0c9d439 100644 --- a/src/panier.c +++ b/src/panier.c @@ -28,4 +28,57 @@ void clientConstraint(float *weight, float *volume, float *price) printf("Erreur: le prix doit être positif, entrez votre budget maximum ou -1 si vous n'en avait pas: "); scanf("%f", price); } +} + +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; + 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) + { + 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) + { + 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; + 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; + } + } + } + } + return 0 } \ No newline at end of file