diff --git a/app b/app index 98703f1..d305a93 100755 Binary files a/app and b/app differ diff --git a/donnee/client.txt b/donnee/client.txt index 9edf4e1..40223f2 100644 --- a/donnee/client.txt +++ b/donnee/client.txt @@ -1,4 +1,4 @@ -32 0 0 -660 30.00 0 -5079 75.50 0 -8043 50.50 1 +32 0.00 0 +660 19.55 0 +5079 75.50 0 +8043 50.50 1 diff --git a/src/app/core_logic/client.c b/src/app/core_logic/client.c index 9ed649a..d871d19 100644 --- a/src/app/core_logic/client.c +++ b/src/app/core_logic/client.c @@ -226,3 +226,36 @@ void reinitialiser_panier(int panier[], int quantites[], int *taillePanier) { *taillePanier = 0; printf("Panier réinitialisé avec succès.\n"); } + +void deduire_cagnotte(int numeroClient, float montant, int numeros[], float cagnottes[], int nombreClients, int suspendus[]) { + int clientIndex = -1; + for (int i = 0; i < nombreClients; i++) { + if (numeros[i] == numeroClient) { + clientIndex = i; + break; + } + } + + if (clientIndex == -1) { + printf("Client non trouvé. Impossible de déduire la cagnotte.\n"); + return; + } + + if (cagnottes[clientIndex] < montant) { + printf("Cagnotte insuffisante. Impossible de déduire la cagnotte.\n"); + return; + } + + cagnottes[clientIndex] -= montant; + + FILE *fe; + fe = fopen("donnee/client.txt", "w"); + if (fe == NULL) { + perror("fopen"); + return; + } + for (int i = 0; i < nombreClients; i++) { + fprintf(fe, "%d %.2f %d\n", numeros[i], cagnottes[i], suspendus[i]); + } + fclose(fe); +} \ No newline at end of file diff --git a/src/app/core_logic/client.h b/src/app/core_logic/client.h index 9653efd..c7d8bfa 100644 --- a/src/app/core_logic/client.h +++ b/src/app/core_logic/client.h @@ -17,4 +17,6 @@ void affiche_recap_panier(int panier[], int taillePanier, int references[], floa float prixUnitaire[], int quantites[]); void modifier_quantite_article_panier(int panier[], int quantites[], int *taillePanier); void reinitialiser_panier(int panier[], int quantites[], int *taillePanier); +void deduire_cagnotte(int numeroClient, float montant, int numeros[], float cagnottes[], int nombreClients, int suspendus[]); + #endif //SAE_101_CLIENT_H diff --git a/src/app/interface/interface_client.c b/src/app/interface/interface_client.c index c6d1767..57da344 100644 --- a/src/app/interface/interface_client.c +++ b/src/app/interface/interface_client.c @@ -110,6 +110,22 @@ void global_client() { reinitialiser_panier(panier, quantites, &taillePanier); break; case 9: + printf("Voulez-vous déduire de votre cagnotte avant de quitter ? (1 pour Oui, 0 pour Non) : "); + int choixCagnotte; + scanf("%d", &choixCagnotte); + if (choixCagnotte == 1) { + // Demander le montant à déduire de la cagnotte + float montant; + printf("Entrez le montant à déduire de votre cagnotte : "); + scanf("%f", &montant); + + // Appeler la fonction pour déduire la cagnotte + deduire_cagnotte(numeroClient, montant, numeros, cagnottes, nombreClients, suspendus); + + // Informer le client que la cagnotte a été déduite + printf("Le montant a été déduit de votre cagnotte.\n"); + } + printf("Au revoir !\n"); return; default: