ajout de l'alerte lorsque contrainte dépassée et de l'utilisation de la cagnotte

doc
Louis GERMAIN 2 years ago
parent eaf545a014
commit b8f716d3ed

@ -38,3 +38,4 @@ 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);

@ -29,3 +29,56 @@ void clientConstraint(float *weight, float *volume, float *price)
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<tlog; i++)
{
totalWeight += tabWeight[i];
totalVolume += tabVolume[i];
if (priceConstraint != -1)
totalPrice += tabUnitPrice[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);
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
}
Loading…
Cancel
Save