From 5a504025197894e178c8e58c5cf2c7cd28b35eac Mon Sep 17 00:00:00 2001 From: "julien.abadie" Date: Sat, 4 Nov 2023 15:29:43 +0100 Subject: [PATCH] Ajout des fonctions basket_del_article et reinit_basket et correction de bugs --- src/main.h | 3 +++ src/panier.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 61 insertions(+), 3 deletions(-) diff --git a/src/main.h b/src/main.h index 692a0b3..e5feada 100644 --- a/src/main.h +++ b/src/main.h @@ -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); + diff --git a/src/panier.c b/src/panier.c index c51adfa..6281378 100644 --- a/src/panier.c +++ b/src/panier.c @@ -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); + + return tlog_basket; +} - tlog_basket = tlog_basket+1; +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_delindex_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; + } + + } + } \ No newline at end of file