From 0090a249567b5842faa983f22ebc337d3d75b7fc Mon Sep 17 00:00:00 2001 From: "julien.abadie" Date: Wed, 1 Nov 2023 16:34:40 +0100 Subject: [PATCH] Ajout de la fonction --- src/main.h | 3 ++- src/panier.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/src/main.h b/src/main.h index ebe971f..6bdd72c 100644 --- a/src/main.h +++ b/src/main.h @@ -40,4 +40,5 @@ 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); \ No newline at end of file +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); \ No newline at end of file diff --git a/src/panier.c b/src/panier.c index cb5785e..13fab56 100644 --- a/src/panier.c +++ b/src/panier.c @@ -81,4 +81,56 @@ int constraintExceeded(float weightConstraint, float volumeConstraint, float *pr } } return 0; +} + +/** + * @brief Ajoute un article au panier et calcule les différents attributs pour la fonction `display_basket` + * @param tab_reference: tableau des références des articles + * @param weight: tableau des poids des articles + * @param volume: tableau du volume des articles + * @param unitPrice: tableau du prix unitaire des articles + * @param cagnotte: pointeur indiquant la valeur de la cagnotte + * @param basket_tab_ref: tableau des références du panier + * @param basket_tab_qte: tableau de la quantité de l'article du panier + * @param tlog: taille logique du tableau `tab_reference` + * @param tlog_basket: taille logique du panier + * @return taille logique du panier +*/ +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 ref_to_add, qte_to_add, trouve, index_ajout, i; + float total_weight=0, total_volume=0, total_price=0, total_cagnotte=0; + printf("Quelle référence souhaitez-vous ajouter au panier?"); + scanf("%d", &ref_to_add); + index_ajout = searchTab(tab_reference, ref_to_add, tlog, &trouve); + while (trouve == 0) + { + printf("L'élément que vous souhaitez ajouter n'existe pas, ressayez s'il vous plaît"); + scanf("%d", &ref_to_add); + index_ajout = searchTab(tab_reference, ref_to_add, tlog, &trouve); + } + basket_tab_ref[index_ajout] = ref_to_add; + printf("Quelle quantité de cet article souhaitez-vous ajouter au panier?"); + scanf("%d", &qte_to_add); + while (qte_to_add <= 0) + { + printf("Vous ne pouvez pas ajouter une quantité nulle ou négative ressayez"); + scanf("%d", &qte_to_add); + } + basket_tab_qte[index_ajout] = ref_to_add; + + for (i=0; i