deduire_cagnotte works

Signed-off-by: Mathéo Hersan <matheohersan@MacBook-Pro-de-Matheo.local>
pull/3/head
Mathéo Hersan 2 years ago
parent 94037a556d
commit 24bdef86c5
No known key found for this signature in database
GPG Key ID: 4EF19C64D78EC91B

BIN
app

Binary file not shown.

@ -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

@ -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);
}

@ -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

@ -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:

Loading…
Cancel
Save