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
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);

@ -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<tlog; i++)
for (i=0; i<tlogBasket; i++)
{
totalWeight += tabWeight[i] * tabQuantity[i];
totalVolume += tabVolume[i] * tabQuantity[i];
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)
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;
}
}
}
}

Loading…
Cancel
Save