diff --git a/commun.c b/commun.c index fcbe6b0..ae345bd 100644 --- a/commun.c +++ b/commun.c @@ -9,152 +9,107 @@ int Fillvar(int *tAd, char tnom[][15], char tpnom[][15], int *tage, int *tstate, int *tacti, int *tpasseoupas, int *tptsbought, int *tptsbonus, char *tcateg, int tmax)//lis le fichier et met les valeurs dans les tableaux { - FILE *f; - f = fopen("donneeClient.don", "r"); - if (f == NULL) - { - printf("Problème d'ouverture du fichier Clients..."); - return -1; - } - int i = 0; - int numAd, age, state, acti, passeoupas, ptsbought, ptsbonus; - char categ, fnom[15], fprenom[15]; - - fscanf(f, "%6d", &numAd); - fscanf(f, "%s", fnom); - fscanf(f, "%s", fprenom); - fscanf(f, "%2d", &age); - fscanf(f, "%d", &state); - fscanf(f, "%d", &acti); - fscanf(f, "%d", &passeoupas); - fscanf(f, "%2d", &ptsbought); - fscanf(f, "%2d%*c", &ptsbonus); - fscanf(f, "%c", &categ); - - while (!feof(f)) - { - if (i == tmax) - { - printf("Problème de gestion: trop de clients enregistrés à ce jour"); - return -1; - } - - - tAd[i] = numAd; - strcpy(tnom[i], fnom); - strcpy(tpnom[i], fprenom); - tage[i] = age; - tstate[i] = state; - tacti[i] = acti; - tpasseoupas[i] = passeoupas; - tptsbought[i] = ptsbought; - tptsbonus[i] = ptsbonus; - tcateg[i] = categ; - - i++; - - fscanf(f, "%6d", &numAd); - fscanf(f, "%s", fnom); - fscanf(f, "%s", fprenom); - fscanf(f, "%2d", &age); - fscanf(f, "%d", &state); - fscanf(f, "%d", &acti); - fscanf(f, "%d", &passeoupas); - fscanf(f, "%2d", &ptsbought); - fscanf(f, "%2d%*c", &ptsbonus); - fscanf(f, "%c", &categ); - - } - fclose(f); - return i; -} -void GereAdhérent(void) -{ - int tAd[TAILLE], tage[TAILLE], tstate[TAILLE], tacti[TAILLE], tpasseoupas[TAILLE], tptsbought[TAILLE], tptsbonus[TAILLE], place, nbacti, chxacti, numAd, ret, insuf; - char tcateg[TAILLE], nom[TAILLE], pnom[TAILLE], fnom[TAILLE], fpnom[TAILLE], bCard, tnom[TAILLE][15], tpnom[TAILLE][15], action, choix, recharge; - place = Fillvar(tAd, tnom, tpnom, tage, tstate, tacti, tpasseoupas, tptsbought, tptsbonus, tcateg, 500); - - bCard = Card();//demande si carte avec client ou non + FILE *f; + f = fopen("donneeClient.don", "r"); + if (f == NULL) + { + printf("Problème d'ouverture du fichier Clients..."); + return -1; + } + int i = 0; + int numAd, age, state, acti, passeoupas, ptsbought, ptsbonus; + char categ, fnom[15], fprenom[15]; + + fscanf(f, "%d%*c", &numAd); + fscanf(f, "%s%*c", fnom); + fscanf(f, "%s%*c", fprenom); + fscanf(f, "%d%*c", &age); + fscanf(f, "%d%*c", &state); + fscanf(f, "%d%*c", &acti); + fscanf(f, "%d%*c", &passeoupas); + fscanf(f, "%d%*c", &ptsbought); + fscanf(f, "%d%*c", &ptsbonus); + fscanf(f, "%c%*c", &categ); + + while (!feof(f)) + { + if (i == tmax) + { + printf("Problème de gestion: trop de clients enregistrés à ce jour"); + return -1; + } + tAd[i] = numAd; + strcpy(tnom[i], fnom); + strcpy(tpnom[i], fprenom); + tage[i] = age; + tstate[i] = state; + tacti[i] = acti; + tpasseoupas[i] = passeoupas; + tptsbought[i] = ptsbought; + tptsbonus[i] = ptsbonus; + tcateg[i] = categ; - if (bCard == 'N')// si client n'a pas la carte - { - Name(nom, pnom); + i++; - puts("Recherche de la carte !"); + fscanf(f, "%d%*c", &numAd); + fscanf(f, "%s%*c", fnom); + fscanf(f, "%s%*c", fprenom); + fscanf(f, "%d%*c", &age); + fscanf(f, "%d%*c", &state); + fscanf(f, "%d%*c", &acti); + fscanf(f, "%d%*c", &passeoupas); + fscanf(f, "%d%*c", &ptsbought); + fscanf(f, "%d%*c", &ptsbonus); + fscanf(f, "%c%*c", &categ); - place = FindData(nom, pnom, tnom, tpnom, tpasseoupas, tptsbought, &action, 500); - if (place == -1) - { - return; - } } - if (bCard == 'O') - { - printf("Numéro carte : \t"); - scanf("%*c%d", &numAd); - ret = FindN(tAd, numAd, tpasseoupas, 500); - if (ret == -1) - { - GereAdhérent(); - } - } + fclose(f); + return i; +} - - ChoiceMenu(&choix); - if (choix == 'A') - { - printf("La carte dispose de %d points.\n", tptsbought[place]);//infos sur ses points - ChoiceMenu(&choix); - } - if (choix == 'R') - { - Recharge(tptsbought, place, tcateg); - ChoiceMenu(&choix); - } +void GereAdhérent(void) +{ + int tAd[TAILLE], tage[TAILLE], tstate[TAILLE], tacti[TAILLE], tpasseoupas[TAILLE], tptsbought[TAILLE], tptsbonus[TAILLE], place, nbacti, choix, chxacti, numAd, ret, insuf, day = 0; + char tcateg[TAILLE], nom[TAILLE], pnom[TAILLE], fnom[TAILLE], fpnom[TAILLE], bCard, tnom[TAILLE][15], tpnom[TAILLE][15], action, recharge; + place = Fillvar(tAd, tnom, tpnom, tage, tstate, tacti, tpasseoupas, tptsbought, tptsbonus, tcateg, 500); + bCard = Card();//demande si carte avec client ou non - if (choix == 'C') - { - printf("Nombre d'activités souhaitées ? (max 3)\n"); - scanf("%d", &nbacti); - while (nbacti < 0 || nbacti > 3) - { - printf("Nombre d'activités incorrect (max 3)\n"); - scanf("%d", &nbacti); - } - chxacti = ChoiceActi(nbacti, tacti); - CheckPts(tptsbonus, tptsbought, tpasseoupas, tacti, tcateg, place, chxacti, &insuf); - if (insuf == 1) + if (bCard == 'N')// si client n'a pas la carte { - printf("Nombre de points insuffisants : Recharge (R) ou Quitter (Q)"); - scanf("%c%*c", &recharge); - if (recharge == 'R') + Name(nom, pnom); + + puts("Recherche de la carte !"); + + place = FindData(nom, pnom, tnom, tpnom, tpasseoupas, tptsbought, &action, 500); + if (place == -1) { - Recharge(tptsbought, place, tcateg); + return; } - else + } + + if (bCard == 'O') + { + printf("Numéro carte : \t"); + scanf("%*c%d", &numAd); + ret = FindN(tAd, numAd, tpasseoupas, 500); + if (ret == -1) { - ChoiceMenu(&choix); + main(); } } - ChoiceMenu(&choix); - - } - - if (choix == 'Q') - { - //menuglobal() - return; - } + choix = ChoiceMenu(); + Loop(tAd, tnom, tpnom, tage, tstate, tacti, tpasseoupas, tptsbought, tptsbonus, tcateg, &choix, &insuf, place, nbacti); } + char Card(void)//demande si client a la carte { char bCard; @@ -177,6 +132,7 @@ void Name( char *nom, char *prenom)//demande nom et prénom + int FindData(char *nom, char *pnom, char tnom[][15], char tpnom[][15], int *tpasseoupas, int *tptsbought, char *action, int tmax) { int i, found = 0, testnom, testpnom; @@ -252,12 +208,7 @@ void Recharge(int *tptsbought, int place, char *tcateg) { int dizpts, topay, nbpts; printf("Combien de dizaines de points souhaitez-vous acheter ?\n"); - scanf("%d", &dizpts); - while (dizpts > 100 || dizpts < 0) - { - printf("Veuillez entrer un nombre correct de dizaines de points\n"); - scanf("%d", &dizpts); - } + scanf("%d%*c", &dizpts); if (tcateg[place] == 'E') { @@ -265,7 +216,7 @@ void Recharge(int *tptsbought, int place, char *tcateg) topay = dizpts * 2; tptsbought[place] += nbpts; - printf("Vous avez désormais %d points sur la carte, vous nous devez %d €\n", tptsbought[place], topay); + printf("Vous avez désormais %d points sur la carte, vous nous devez %d\n", tptsbought[place], topay); } if (tcateg[place] == 'S') @@ -274,7 +225,7 @@ void Recharge(int *tptsbought, int place, char *tcateg) topay = dizpts * 4; tptsbought[place] += nbpts; - printf("Vous avez désormais %d points sur la carte, vous nous devez %d €\n", tptsbought[place], topay); + printf("Vous avez désormais %d points sur la carte, vous nous devez %d\n", tptsbought[place], topay); } if (tcateg[place] == 'A') @@ -283,7 +234,7 @@ void Recharge(int *tptsbought, int place, char *tcateg) topay = dizpts * 6; tptsbought[place] += nbpts; - printf("Vous avez désormais %d points sur la carte, vous nous devez %d €\n", tptsbought[place], topay); + printf("Vous avez désormais %d points sur la carte, vous nous devez %d\n", tptsbought[place], topay); } } @@ -294,8 +245,8 @@ int Acti(int i) { int acti; printf("Choix de l'activité %d: badminton (1) | football (2) | zumba (3) | musculation (4) | squash (5) \n", i); - scanf("%*c%d%*c", &acti); - while (acti != 1 && acti != 2 && acti != 3 && acti != 4 && acti != 5) + scanf("%d%*c", &acti); + while (acti <= 0 && acti >= 6) { printf("Veuillez entrer un nombre d'activité correct (badminton (1) | football (2) | zumba (3) | musculation (4) | squash (5))\n"); scanf("%d%*c", &acti); @@ -335,15 +286,17 @@ int ChoiceActi(int nbacti, int *tacti) -void ChoiceMenu(char *choix) +int ChoiceMenu(void) { - printf("Recharge carte (R) | Afficher points (A) | Choix activités (C) | Quitter (Q)\n"); - scanf("%c%*c", choix); - while (*choix != 'R' && *choix != 'A' && *choix != 'C' && *choix != 'Q') + int choix; + printf("Recharge carte (1) | Afficher points (2) | Choix activités (3) | Quitter (4)\n"); + scanf("%d", &choix); + while (choix > 4 || choix < 1) { - printf("Entrer un caractère correct R | A | C | Q \n"); - scanf("%c%*c%*c", choix); + printf("Entrer un caractère correct 1 | 2 | 3 | 4 \n"); + scanf("%d%*c", &choix); } + return choix; } @@ -362,7 +315,7 @@ void CheckPts(int *tptsbonus, int *tptsbought, int *tpasseoupas, int *tacti, cha if (ptsneeded <= tptsbought[place]) { ("Points suffisants, confirmation ? (O/N) \n"); - scanf("%c%*c", &confirm); + scanf("%*c%c%*c", &confirm); if (confirm == 'O') { tptsbought[place] -= ptsneeded; @@ -457,6 +410,54 @@ void Save(int *tAd, char tnom[][15], char tpnom[][15], int *tage, int *tstate, i +void Loop(int *tAd, char tnom[][15], char tpnom[][15], int *tage, int *tstate, int *tacti, int *tpasseoupas, int *tptsbought, int *tptsbonus, char *tcateg, int *choix, int *insuf, int place, int nbacti) +{ + int chxacti; + char recharge; + while (*choix != 4) + { + + if (*choix == 2) + { + printf("La carte dispose de %d points.\n", tptsbought[place]);//infos sur ses points + } + + if (*choix == 1) + { + Recharge(tptsbought, place, tcateg); + } + + if (*choix == 3) + { + printf("Nombre d'activités souhaitées ? (max 3)\n"); + scanf("%*c%d", &nbacti); + while (nbacti < 0 || nbacti > 3) + { + printf("Nombre d'activités incorrect (max 3)\n"); + scanf("%*c%d", &nbacti); + } + + chxacti = ChoiceActi(nbacti, tacti); + CheckPts(tptsbonus, tptsbought, tpasseoupas, tacti, tcateg, place, chxacti, insuf); + if (*insuf == 1) + { + printf("Nombre de points insuffisants : Recharge (R) ou Quitter (Q)"); + scanf("%*c%c%*c", &recharge); + if (recharge == 'R') + { + Recharge(tptsbought, place, tcateg); + } + } + } + + *choix = ChoiceMenu(); + } +} + + + + + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -505,8 +506,8 @@ void fAffichage1Client(int *tAd, char tnom[][15], char tpnom[][15], int *tage,in if(noClient==-1) { return; - } - + } + } } printf(" N° Client\t Nom\t Prénom\t Age\t Tarif\t Nombre de points \t \n"); @@ -553,7 +554,7 @@ void cptAct(int *bad, int *muscu, int *foot, int *squa, int * zumba, int chx) } -//Calcul et affiche le nombre d'entrée +//Calcul et affiche le nombre d'entrée void affNbParAct(int *tacti, int tlog) { int chx1, chx2, chx3, bad, muscu, foot, squa, zumba, totbad, totmuscu, totfoot, totsqua, totzumba, i; @@ -678,12 +679,12 @@ void Index(void) int tAd[TAILLE], tage[TAILLE], tstate[TAILLE], tacti[TAILLE], tpasseoupas[TAILLE], tptsbought[TAILLE], tptsbonus[TAILLE], place, nbacti, chxacti, numAd, ret, n, VSUIVANTE, next, choix=0; char tcateg[TAILLE], nom[TAILLE], pnom[TAILLE], fnom[TAILLE], fpnom[TAILLE], bCard, member, tnom[TAILLE][15], tpnom[TAILLE][15], action, retourmenu; - + n=Fillvar(tAd, tnom, tpnom, tage, tstate, tacti, tpasseoupas, tptsbought, tptsbonus, tcateg, 500); FILE *fx; - + fx=fopen("x.don","r"); - + if (fx==NULL) {printf("erreur"); return;} @@ -693,7 +694,7 @@ void Index(void) while(!feof(fx)) { fscanf(fx, "%d", &next); - + if ( next> VSUIVANTE) { VSUIVANTE=next; @@ -713,7 +714,7 @@ void Index(void) //printf("\nTapez h pour une aide\n"); scanf("%d%*c", &choix); - + while (1 > choix || choix> 6) { printf("\nEntrez soit 1, soit 2.\t"); @@ -734,17 +735,17 @@ void Index(void) printf("\nTapez la lettre O pour revenir au menu.\t"); scanf("%*c%c%*c", &retourmenu); } - + if (retourmenu == 'O') Index(); - + } -*/ +*/ if (choix == 1) { creationCompte( &VSUIVANTE); } - + if (choix == 2) { menuAff(tAd, tnom, tpnom, tage, tstate, tacti, tpasseoupas, tptsbought, tptsbonus, tcateg, 500, n); @@ -764,26 +765,26 @@ void creationCompte(int *VSUIVANTE) FILE *fe, *fx, *fn; fe= fopen("donneClient.don", "a"); fx= fopen("x.don","a"); - - + + if (fe==NULL) { printf(" Erreur ouverture fichier"); } - + printf("\nEntrez votre nom\n"); scanf("%s%*c", nom); - + printf("\nEntrez votre prenom\n"); scanf("%s%*c", prenom); - + printf("\nEntrez votre age\n"); scanf("%d%*c", &age); - + printf("Avez-vous un tarif spécial: Etudiant(E), Senior(S), aucun(A)?\n"); scanf("%c%*c", &categorie); - - + + fprintf(fe,"\n%d\t",*VSUIVANTE); fprintf(fe,"%s\t",nom); fprintf(fe,"%s\t",prenom); @@ -798,17 +799,17 @@ void creationCompte(int *VSUIVANTE) *VSUIVANTE=*VSUIVANTE+1; fprintf(fx,"\n%d",*VSUIVANTE); - + printf("Ajoutez un contact?(O/N)\n"); scanf("%c%*c", &retour); - + if (retour == 'O') creationCompte(VSUIVANTE); else return; } - + void menuAff (int *tAd, char tnom[][15], char tpnom[][15], int *tage, int *tstate, int *tacti, int *tpasseoupas, int *tptsbought, int *tptsbonus, char *tcateg, int tmax, int n) { int choix, noClient; @@ -825,4 +826,3 @@ void menuAff (int *tAd, char tnom[][15], char tpnom[][15], int *tage, int *tstat fAffichage1Client(tAd, tnom, tpnom, tage, tstate, n, noClient, tptsbought, tcateg); } } - diff --git a/hCommun.h b/hCommun.h index 42674cc..d1165ac 100644 --- a/hCommun.h +++ b/hCommun.h @@ -7,7 +7,7 @@ int affNbmEntree( int *tpasseoupas, int tlog); void cptAct(int *bad, int *muscu, int *foot, int *squa, int * zumba, int chx); void affNbParAct(int *tacti, int tlog); void suppr1Client(int *tAd, char tnom[][15], char tpnom[][15], int *tage, int *tstate, int *tacti, int *tpasseoupas, int *tptsbought, int *tptsbonus, char *tcateg, int *n, int tmax); -char Card(void);//check si le client a la carte +char Card(void);//check si le client a la carte void Index(void); void creationCompte(int *VSUIVANTE); void fRecherche(int *tAd, int n, int noClient, int *coderet, int *rang); @@ -22,4 +22,5 @@ int FindN(int *tAd, int numAd, int *tpasseoupas, int tmax); void CheckPts(int *tptsbonus, int *tptsbought, int *tpasseoupas, int *tacti, char *tcateg, int place, int acti, int *insuf); void GereAdhérent(void); void Save(int *tAd, char tnom[][15], char tpnom[][15], int *tage, int *tstate, int *tacti, int *tpasseoupas, int *tptsbought, int *tptsbonus, char *tcateg, int tmax, int place); +void Loop(int *tAd, char tnom[][15], char tpnom[][15], int *tage, int *tstate, int *tacti, int *tpasseoupas, int *tptsbought, int *tptsbonus, char *tcateg, int *choix, int *insuf, int place, int nbacti); void menuAff (int *tAd, char tnom[][15], char tpnom[][15], int *tage, int *tstate, int *tacti, int *tpasseoupas, int *tptsbought, int *tptsbonus, char *tcateg, int tmax, int n);