modification de la fonction du dépassement des contraintes pour correspondre au fctment du panier

doc
Louis GERMAIN 1 year ago
parent 2b29a431b6
commit 0032b79a49

@ -40,7 +40,7 @@ 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 *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); 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); 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); int reinit_basket(int tlog_basket);

@ -51,52 +51,55 @@ void clientConstraint(float *weight, float *volume, float *price)
* @return an integer value. * @return an integer value.
*/ */
// TODO réécrire cette documentation // 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; float totalWeight = 0, totalVolume = 0, totalPrice = 0, cagnotteUse;
int i; for (i=0; i<tlogBasket; i++)
for (i=0; i<tlog; i++)
{ {
totalWeight += tabWeight[i] * tabQuantity[i]; index = searchTab(tabItemRef, tabBasketRef[i], tlogItem, &found);
totalVolume += tabVolume[i] * tabQuantity[i]; if (found == 1)
if (*priceConstraint != -1)
totalPrice += tabUnitPrice[i] * tabQuantity[i];
if (totalWeight > 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); totalWeight += tabWeight[index] * tabBasketQuantity[i];
return -1; totalVolume += tabVolume[index] * tabBasketQuantity[i];
} if (*priceConstraint != -1)
if (*priceConstraint != -1 && totalPrice > *priceConstraint) totalPrice += tabPrice[index] * tabBasketQuantity[i];
{ if (totalWeight > weightConstraint)
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"); 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; 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); printf("Attention, la contrainte de volume maximum a été dépassé de %.2f, veuillez retirer un article\n", totalVolume - volumeConstraint);
scanf("%f", &cagnotteUse); return -1;
if (cagnotteUse == -1) }
return -1; if (*priceConstraint != -1 && totalPrice > *priceConstraint)
while (cagnotteUse > *cagnotte || totalPrice-cagnotteUse > *priceConstraint) {
printf("Attention, la contrainte de budget maximum a été dépassé de %.2f\n", totalPrice - *priceConstraint);
if (*cagnotte < totalPrice)
{ {
if (cagnotteUse > *cagnotte) printf("Le prix total excédant votre cagnotte, veuillez retirer un article\n");
printf("Erreur: vous ne pouvez pas utiliser plus que vous n'avez, réessayez ou entrer -1 si vous souhaitez retirer un article: "); return -1;
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); 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); scanf("%f", &cagnotteUse);
if (cagnotteUse == -1) if (cagnotteUse == -1)
return -1; return -1;
*cagnotte -= cagnotteUse; while (cagnotteUse > *cagnotte || totalPrice-cagnotteUse > *priceConstraint)
*priceConstraint += cagnotteUse; {
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;
}
} }
} }
} }

Loading…
Cancel
Save