You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

144 lines
2.7 KiB

#include <stdio.h>
#include "SAE.h"
#define LEN 100
int chargementClients(int *t1, int *t2, int tmax){ //charge les tableaux
FILE *fe;
int numClient, points;
fe=fopen("Adherents.txt","r");
if(fe==NULL){
printf("Probleme ouverture fichier");
return -1;}
int i=0;
fscanf("%d%*c %d%*c",&numClient,&points);
while(feof(fe)==0){
if(i>tmax){
printf("taille du tableau dépassée \n");
fclose(fe);
return-1;}
t1[i]=numClient;
t2[i]=points;
fscanf("%d%*c %d%*c",&numClient,&points);
i++;
}
fclose(fe);
return i;
}
int rechercheAdherent(int *t1, int *t2,int val,int LENlo,int *trouve){//recherche un adherent et affiche sont identifiant
int i;
for (i=0;i<LENlo;i++){
if (val==t1[i]){
*trouve=0;
return i;}
if (val<t1[i]){
*trouve=1;
return i;}
}
return i;
}
void choixAdmin(void){//choix menu admin ou adherent
char admin;
printf("Êtes vous administrateur? (O/N)");
scanf("%c%*c",&admin);
if(admin=='O')
Admin;
if(admin=='N')
Adherent;
}
void Admin(void){//menu admin
int choix;
printf("MENU: \n1)Nouvel adhérent \n2)Créditer une carte \n3)Bloquer une carte \n4)Réactiver une carte \n5)Afficher les données d'un adhérent \n");
scanf("%d",&choix);
if(choix==1)
NouvelAdherent;
if(choix==2)
CreditCarte; //en lien avec adherents
if(choix==3)
Bloquercarte;
if(choix==4)
RectiverCarte;
if(choix==5)
DonneesAdherent;//en lien avec adherent
}
void Adherent(void){//menu adherent
int choix;
printf("MENU: \n1)Choix Activité \n2)Afficher les données d'un adhérent \n3)Créditer une carte \n");
scanf("%d",&choix);
if(choix==1)
ChoixActivite;
if(choix==2)
DonneesAdherent;//en lien avec admin
if(choix==3)
CreditCarte;//en lien avec admin
}
int ChoixActivite(int *t1, int *t2){//choix de l'activité
int activite,trouve,i;
printf("Choisissez une activité: \n1)VolleyBall(30pts) \n2)Natation(15pts) \n3)Randonnée(20pts) \n4)Escalade(35pts) \n");
scanf("%d",&activite);
if(activite==1)
t2[i]=t2[i]-30;
if(activite==2)
t2[i]=t2[i]-15;
if(activite==3)
t2[i]=t2[i]-20;
if(activite==4)
t2[i]=t2[i]-35;
if(t2[i]<0){
printf("Erreur: crédit insuffisant.");
if(activite==1)
t2[i]=t2[i]+30;
if(activite==2)
t2[i]=t2[i]+15;
if(activite==3)
t2[i]=t2[i]+20;
if(activite==4)
t2[i]=t2[i]+35;
}
}
void DonneesAdherent(int *t1, int *t2){
int id,trouve,rech,points;
printf("Saisir un identifiant:");
scanf("%d",&id);
rech=rechercheAdherent(t1,t2,id,LEN,&trouve);
points=t2[rech];
printf("Vous êtes l'adhérent %d, et vous avez %d points.",id,points);
}
void CreditCarte(t1[],t2[]){
int pts;
float prix;
printf("Saisir un nombre de points(10pts=5€)");
scanf("%d",&pts);
while(pts!=>0){
prix=pts*0.5;
printf("Voulez vous saisir plus de points?(10pts=5€)");
scanf("%d",&pts);}
printf("Vous avez acheté %d pts pour %.2f €.",pts,prix);
}