change version of lo.c in commun and .h

master
L0ol4X 2 years ago
parent 9c211d289d
commit 37f349a24a

@ -20,16 +20,16 @@ int Fillvar(int *tAd, char tnom[][15], char tpnom[][15], int *tage, int *tstate,
int numAd, age, state, acti, passeoupas, ptsbought, ptsbonus; int numAd, age, state, acti, passeoupas, ptsbought, ptsbonus;
char categ, fnom[15], fprenom[15]; char categ, fnom[15], fprenom[15];
fscanf(f, "%6d", &numAd); fscanf(f, "%d%*c", &numAd);
fscanf(f, "%s", fnom); fscanf(f, "%s%*c", fnom);
fscanf(f, "%s", fprenom); fscanf(f, "%s%*c", fprenom);
fscanf(f, "%2d", &age); fscanf(f, "%d%*c", &age);
fscanf(f, "%d", &state); fscanf(f, "%d%*c", &state);
fscanf(f, "%d", &acti); fscanf(f, "%d%*c", &acti);
fscanf(f, "%d", &passeoupas); fscanf(f, "%d%*c", &passeoupas);
fscanf(f, "%2d", &ptsbought); fscanf(f, "%d%*c", &ptsbought);
fscanf(f, "%2d%*c", &ptsbonus); fscanf(f, "%d%*c", &ptsbonus);
fscanf(f, "%c", &categ); fscanf(f, "%c%*c", &categ);
while (!feof(f)) while (!feof(f))
{ {
@ -53,31 +53,33 @@ int Fillvar(int *tAd, char tnom[][15], char tpnom[][15], int *tage, int *tstate,
i++; i++;
fscanf(f, "%6d", &numAd); fscanf(f, "%d%*c", &numAd);
fscanf(f, "%s", fnom); fscanf(f, "%s%*c", fnom);
fscanf(f, "%s", fprenom); fscanf(f, "%s%*c", fprenom);
fscanf(f, "%2d", &age); fscanf(f, "%d%*c", &age);
fscanf(f, "%d", &state); fscanf(f, "%d%*c", &state);
fscanf(f, "%d", &acti); fscanf(f, "%d%*c", &acti);
fscanf(f, "%d", &passeoupas); fscanf(f, "%d%*c", &passeoupas);
fscanf(f, "%2d", &ptsbought); fscanf(f, "%d%*c", &ptsbought);
fscanf(f, "%2d%*c", &ptsbonus); fscanf(f, "%d%*c", &ptsbonus);
fscanf(f, "%c", &categ); fscanf(f, "%c%*c", &categ);
} }
fclose(f); fclose(f);
return i; return i;
} }
void GereAdhérent(void) 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; 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, choix, recharge; 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); place = Fillvar(tAd, tnom, tpnom, tage, tstate, tacti, tpasseoupas, tptsbought, tptsbonus, tcateg, 500);
bCard = Card();//demande si carte avec client ou non bCard = Card();//demande si carte avec client ou non
if (bCard == 'N')// si client n'a pas la carte if (bCard == 'N')// si client n'a pas la carte
{ {
Name(nom, pnom); Name(nom, pnom);
@ -98,62 +100,15 @@ void GereAdhérent(void)
ret = FindN(tAd, numAd, tpasseoupas, 500); ret = FindN(tAd, numAd, tpasseoupas, 500);
if (ret == -1) if (ret == -1)
{ {
GereAdhérent(); main();
} }
} }
ChoiceMenu(&choix); choix = ChoiceMenu();
Loop(tAd, tnom, tpnom, tage, tstate, tacti, tpasseoupas, tptsbought, tptsbonus, tcateg, &choix, &insuf, place, nbacti);
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);
}
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)
{
printf("Nombre de points insuffisants : Recharge (R) ou Quitter (Q)");
scanf("%c%*c", &recharge);
if (recharge == 'R')
{
Recharge(tptsbought, place, tcateg);
}
else
{
ChoiceMenu(&choix);
}
}
ChoiceMenu(&choix);
}
if (choix == 'Q')
{
//menuglobal()
return;
}
}
char Card(void)//demande si client a la carte char Card(void)//demande si client a la carte
{ {
@ -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 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; int i, found = 0, testnom, testpnom;
@ -252,12 +208,7 @@ void Recharge(int *tptsbought, int place, char *tcateg)
{ {
int dizpts, topay, nbpts; int dizpts, topay, nbpts;
printf("Combien de dizaines de points souhaitez-vous acheter ?\n"); printf("Combien de dizaines de points souhaitez-vous acheter ?\n");
scanf("%d", &dizpts); scanf("%d%*c", &dizpts);
while (dizpts > 100 || dizpts < 0)
{
printf("Veuillez entrer un nombre correct de dizaines de points\n");
scanf("%d", &dizpts);
}
if (tcateg[place] == 'E') if (tcateg[place] == 'E')
{ {
@ -265,7 +216,7 @@ void Recharge(int *tptsbought, int place, char *tcateg)
topay = dizpts * 2; topay = dizpts * 2;
tptsbought[place] += nbpts; 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') if (tcateg[place] == 'S')
@ -274,7 +225,7 @@ void Recharge(int *tptsbought, int place, char *tcateg)
topay = dizpts * 4; topay = dizpts * 4;
tptsbought[place] += nbpts; 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') if (tcateg[place] == 'A')
@ -283,7 +234,7 @@ void Recharge(int *tptsbought, int place, char *tcateg)
topay = dizpts * 6; topay = dizpts * 6;
tptsbought[place] += nbpts; 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; int acti;
printf("Choix de l'activité %d: badminton (1) | football (2) | zumba (3) | musculation (4) | squash (5) \n", i); printf("Choix de l'activité %d: badminton (1) | football (2) | zumba (3) | musculation (4) | squash (5) \n", i);
scanf("%*c%d%*c", &acti); scanf("%d%*c", &acti);
while (acti != 1 && acti != 2 && acti != 3 && acti != 4 && acti != 5) while (acti <= 0 && acti >= 6)
{ {
printf("Veuillez entrer un nombre d'activité correct (badminton (1) | football (2) | zumba (3) | musculation (4) | squash (5))\n"); printf("Veuillez entrer un nombre d'activité correct (badminton (1) | football (2) | zumba (3) | musculation (4) | squash (5))\n");
scanf("%d%*c", &acti); 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"); int choix;
scanf("%c%*c", choix); printf("Recharge carte (1) | Afficher points (2) | Choix activités (3) | Quitter (4)\n");
while (*choix != 'R' && *choix != 'A' && *choix != 'C' && *choix != 'Q') scanf("%d", &choix);
while (choix > 4 || choix < 1)
{ {
printf("Entrer un caractère correct R | A | C | Q \n"); printf("Entrer un caractère correct 1 | 2 | 3 | 4 \n");
scanf("%c%*c%*c", choix); 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]) if (ptsneeded <= tptsbought[place])
{ {
("Points suffisants, confirmation ? (O/N) \n"); ("Points suffisants, confirmation ? (O/N) \n");
scanf("%c%*c", &confirm); scanf("%*c%c%*c", &confirm);
if (confirm == 'O') if (confirm == 'O')
{ {
tptsbought[place] -= ptsneeded; 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();
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -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); fAffichage1Client(tAd, tnom, tpnom, tage, tstate, n, noClient, tptsbought, tcateg);
} }
} }

@ -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 CheckPts(int *tptsbonus, int *tptsbought, int *tpasseoupas, int *tacti, char *tcateg, int place, int acti, int *insuf);
void GereAdhérent(void); 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 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); 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);

Loading…
Cancel
Save