From fd8c1a4bccb7bc3c80472b4f6fb391210ab4f5b3 Mon Sep 17 00:00:00 2001 From: Kyllian CHABANON Date: Wed, 9 Nov 2022 17:07:13 +0100 Subject: [PATCH] Ajout de fonctions --- SAE.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ SAE.h | 6 +++- 2 files changed, 95 insertions(+), 1 deletion(-) diff --git a/SAE.c b/SAE.c index 1f85ed6..0dd887b 100644 --- a/SAE.c +++ b/SAE.c @@ -52,6 +52,96 @@ int Ouverture(int tNoCarte[], int tage[], int tPointsCarte[], int tCarteActive[] fclose(flot); return i; } + +void ajouterPoints(int tNumCarte[], int tPoints[], int tailleLog) +{ + + int numCarte, nbPoints, trouve, index; + char choix; + + printf("Entrez le numéro d'adhérent : "); + scanf("%d", &numCarte); + index = recherche(tNumCarte, tailleLog, numCarte, &trouve); + while (trouve == 0) + { + printf("Numéro de carte non trouvé. Veuillez réessayer.\nEntrez le numéro d'adhérent : "); + scanf("%d", &numCarte); + index = recherche(tNumCarte, tailleLog, numCarte, &trouve); + } + printf("Entrez le nombre de points à ajouter : "); + scanf("%d", &nbPoints); + printf("Vous voulez bien ajouter %d points à la carte n°%d ? (O/n)", nbPoints, numCarte); + scanf("%c%*c", &choix); + if (choix == 'n' || choix == 'N') { + printf("Annulation"); + } + else + { + modifierPoints(tNumCarte, tPoints, tailleLog, numCarte, nbPoints); + } +} + +int modifierPoints(int tNumCarte[], int tPoints[], int tailleLog, int numCarte, int nbPoints) +{ + int index, trouve; + + index = recherche(tNumCarte, tailleLog, numCarte, &trouve); + + if (trouve == 0) + { + printf("Numéro de carte non trouvé. Annulation de l'opétation."); + return 0; + } + else + { + tPoints[index] += nbPoints; + return 1; + } +} + +int recherche(int tab[], int tailleLog, int valeur, int *trouve) +{ + for (int i = 0; i < tailleLog; i++) + { + if (tab[i] == valeur) + { + *trouve = 1; + return i; + } + else if (tab[i] > valeur) + { + *trouve = 0; + return i; + } + } + *trouve = 0; + return tailleLog; +} + + + + + + + + + + + + + + + + + + + + + + + + + /* void pointsBonus() { diff --git a/SAE.h b/SAE.h index f8e73d7..f073f73 100644 --- a/SAE.h +++ b/SAE.h @@ -7,4 +7,8 @@ void testOuverture(); int pointsBonus(); void sauvegarde(); int CreationAdherent(); -int FrequenceCentre();*/ \ No newline at end of file +int FrequenceCentre(); +*/ + +int modifierPoints(int tNumCarte[], int tPoints[], int tailleLog, int numCarte, int points); +int recherche(int tab[], int tailleLog, int valeur, int *trouve); \ No newline at end of file