Ajout des fonctions basket_del_article et reinit_basket et correction de bugs

doc
Julien ABADIE 1 year ago
parent f0edfe731c
commit 5a50402519

@ -43,3 +43,6 @@ 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 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);
int basket_del_article( int basket_tab_ref[], int basket_tab_qte[], int tlog_basket);

@ -148,10 +148,65 @@ int basket_add (int tab_reference[], float weight[], float volume[], float unitP
total_price[i] = total_price + unitPrice[index_ajout]*qte_to_add;
*cagnotte = *cagnotte + *cagnotte*0.10;
tlog_basket = tlog_basket+1;
display_basket();
//paramètres à poser
display_basket( basket_tab_ref[], basket_tab_qte[], weight[], volume[], unitPrice[], *cagnotte, weight_constraint, volume_constraint, tlog, tlog_basket);
tlog_basket = tlog_basket+1;
return tlog_basket;
}
int reinit_basket(int tlog_basket)
{
tlog_basket=0;
// En mettant tlog_basket à 0,
// on fait comme si la taille logique était à 0, faisant que l'on ne considère plus aucun élément des tableaux
return tlog_basket;
}
int basket_del_article( int basket_tab_ref[], int basket_tab_qte[], int tlog_basket)
{
int ref_to_del, trouve, index_to_del, qte_to_del, i;
printf("Quelle référence voulez vous supprimer de votre panier?\n");
scanf("%d",&ref_to_del);
index_to_del = searchTab(basket_tab_ref, ref_to_del, tlog_basket, &trouve);
while (trouve == 0)
{
printf("Erreur, la valeur que vous voulez supprimer n'existe pas, réssayez");
scanf("%d",&ref_to_del);
index_to_del = searchTab(basket_tab_ref, ref_to_del, tlog_basket, &trouve);
}
if (basket_tab_qte[index_to_del]>1)
{
printf("Combien d'articles e ce type voulez-vous supprimer?");
scanf("%d",&qte_to_del);
while(qte_to_del<=0)
{
printf("Erreur, vous ne pouvez pas supprimer un nombre nul ou négatif d'articles, réssayez");
//on pourrait supprimer un nombre nul d'articles,
//mais ça n'a pas de sens car cette fonction à pour but de supprimer des articles
scanf("%d",&qte_to_del);
}
while(basket_tab_qte[index_to_del]-qte_to_del>=0)
{
printf("Erreur, vous ne pouvez pas supprimer plus d'articles que vous n'en avez dans votre panier, ressayez");
scanf("%d",&qte_to_del);
}
if (qte_to_del<basket_tab_qte[index_to_del])
{
basket_tab_qte[index_to_del]=basket_tab_qte[index_to_del]-qte_to_del;
return tlog_basket;
}
else if (qte_to_del==basket_tab_qte[index_to_del])
{
for (i=tlog_basket; i>index_to_del; i--)
{
basket_tab_ref[i]=basket_tab_ref[i+1];
basket_tab_qte[i]=basket_tab_qte[i+1];
}
return tlog_basket-1;
}
}
}
Loading…
Cancel
Save