bonjour,
g creer 5 fonctions permetant : - de lancer le menu du prog
d'ajouter des client
ajouter des factures
lister les clients
lister les factures
tout ceci est enregistrer dans 2 fichiers
ds le fichier client je dois ecrire un nom et un montant de tva
j'aimerai savoir comment faire pour que quand j'entre une facture
et que je rentre le nom du client, il verifie si celui ci existe deja et que si ce n'est pas le cas il y ai un mess disant que le client existe pas et demander s'il fo le creer
lorsque l'on rentre un nom de client qui existe pouvoir lui attribuer le taux de tva qui y fait reference ds le fichier client pour pouvoir calculer le montant de tva de ses facture
et que lorsque l'on liste les clients , il y ai le montant total de toute leur factures
voici le code de mon programme pour l'instant
merci
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#define TAILLE 100
/* definition des structure ------------------------------------*/
struct cli
{
int id_cli;
char nom[25];
float som_due;
int reduc;
int tva;
};
struct fact
{
int id_fact;
char nom_cli[25];
float mont_tot;
};
/* déclaration des fonctions --------------------------------*/
int execmenu();
void encodecli(struct cli *t/*, struct fact *t_fact*/);
void encodefact(struct fact *t_fact /*, struct cli *t*/);
void affiche (struct cli t);
void affiche_fact(struct fact t_fact);
/* Fonction principale -----------------------------------------*/
void main()
{
/*Déclarations ----------------------------------------------*/
struct cli tab[TAILLE];
struct fact tab_fact[TAILLE];
int choi;
tab_fact->mont_tot = 0;
/* Traitement -----------------------------------------------*/
do
{
choi=execmenu();
switch (choi)
{
case 1: encodecli(tab/*, tab_fact*/);
break;
case 2: encodefact(tab_fact/*, tab*/);
break;
case 3: affiche (*tab);
break;
case 4: affiche_fact(*tab_fact);
break;
case 5: printf("choix 5");
break;
case 99: printf("Aurevoir");
break;
}
}
while (choi!=99);
}
/* fonction execmenu ----------------------------------------*/
int execmenu()
{
int choix;
clrscr();
printf("\n\n\n\n\n\n\n\n");
printf(" ******************************************\n");
printf(" * <1> Ajouter un client *\n");
printf(" * <2> Ajouter une facture *\n");
printf(" * <3> Consulter la liste des clients *\n");
printf(" * <4> Consulter la liste des factures *\n");
printf(" * <5> Lister les mauvais payeur *\n");
printf(" * <99> quitter *\n");
printf(" * Votre choix : *\n");
printf(" ******************************************\n");
do
{
scanf("%d",&choix);
}
while (choix!=1 && choix!=2 && choix!=3 && choix!=4 && choix!=5 && choix!=99);
return choix;
}
/*fonction d'encodage des client ----------------------------*/
void encodecli(struct cli *t/*, struct fact *t_fact*/)
{
FILE *ptr;
int ok,nbrenreg=1;
char choix;
ptr=fopen("acces.dat","a+b");
fseek(ptr, 0, SEEK_END);
nbrenreg = ftell(ptr)/sizeof(struct cli);
t->id_cli = nbrenreg;
if(ptr!=NULL)
{
choix='o';
while(choix == 'o')
{
clrscr();
printf("Client n°%d",t->id_cli+1);
printf("\nentrer le nom :");
scanf("%s",t->nom);
printf("entrer le taux de la tva, 25 ou 12:");
scanf("%d",&t->tva);
t->id_cli++;
fflush(stdin);
fseek(ptr,0,SEEK_END);
fwrite(t,sizeof(*(t)),1,ptr);
do
{
ok=0;
printf("Nouvelle fiche (o/n) ?");
choix = getchar();
choix=tolower(choix);
if(choix!='o' && choix!='n')
{
printf("\nRépondez \"o\" ou \"n\" \n");
ok=1;
}
}
while(ok == 1);
}// fin while ok
}// fin if ptr NULL
fclose(ptr);
}
/*fonction d'encodage des Facture ----------------------------*/
void encodefact(struct fact *t_fact /*,struct cli *t*/)
{
FILE *ptfact;
//FILE *ptr2;
int rep_fact,nbrfact=1;
int art=0;
float prix=0;
int quant=0;
float total=0;
float temp=0;
float somme=0;
ptfact = fopen("fact.dat","a+b");
fseek(ptfact,0,SEEK_END);
nbrfact = ftell(ptfact)/sizeof(struct fact);
t_fact->id_fact = nbrfact;
//ptr2=fopen("acces.dat","a+b");
//t_fact->id_fact = 1;
do
{
clrscr();
printf("Facture n°%d",t_fact->id_fact);
printf("\nentrer le numero de l'article:");
scanf("%d", &art);
printf("entrer le prix de l'article:");
scanf("%f", &prix);
printf("entrer le nombre d'aricle:");
scanf("%d", &quant);
somme = prix*quant;
total += somme;
t_fact->mont_tot+=temp;
fflush(stdin);
//fseek(ptfact,0,SEEK_END);
//fwrite(t_fact,sizeof(*(t_fact)),1,ptfact);
printf("voulez vous continuer? 1 pour oui, 2 pour non\n");
scanf("%d",&rep_fact);
}
while(rep_fact==1);
if (total > 1200)
temp = total-(total/100*3);
else
if(total > 500)
temp = total - total/100;
else
if(total < 500)
temp = total;
t_fact->mont_tot=temp;
//t->som_due+=t_fact->mont_tot; atention montant tota pas pris en compte
//t_fact->id_fact++;
//fflush(stdin);
//fwrite(t,sizeof(*(t)),1,ptr2);
fseek(ptfact,0,SEEK_END);
fwrite(t_fact,sizeof(*(t_fact)),1,ptfact);
printf("le montant de la facture total est de %2.f\n",t_fact->mont_tot);
//printf("le montant total a payer est de %2.f\n",t->som_due); idem ici
t_fact->id_fact++;
getch();
fclose(ptfact);
//fclose(ptr2);
}
//Affichage du contenu du fichier principal
void affiche(struct cli t)
{
FILE *ptr;
ptr=fopen("acces.dat","r");
fseek(ptr,0,SEEK_SET);
fread(&t,sizeof(t),0,ptr);
clrscr();
while(fread(&t,sizeof(struct cli),1,ptr) != 0)//(!feof(ptr))
{
printf("\n Numéro Client : %d, Nom : %s, tva : %d",t.id_cli,t.nom,t.tva);
//cli-1 car incrémentation par avance à l'encode
printf("\n le montant a payer est de %f",t.som_due);
}
printf("\n\n Appuyer sur une touche pour revenir au menu");
getch();
fclose(ptr);
}
//Affichage du contenu des facture
void affiche_fact(struct fact t_fact)
{
FILE *ptfact;
ptfact=fopen("fact.dat","rb");
fseek(ptfact,0,SEEK_SET);
fread(&t_fact,sizeof(t_fact),0,ptfact);
clrscr();
while(fread(&t_fact,sizeof(struct fact),1,ptfact) != 0)//(!feof(ptfact))
//while(!feof(ptfact))
{
printf("\nNum Facture: %d Nom du client: %s Montant total: %2.f",t_fact.id_fact,t_fact.nom_cli,t_fact.mont_tot);
//fread(&t_fact,sizeof(t_fact),0,ptfact);
}
printf("\n\n Appuyer sur une touche pour revenir au menu");
getch();
fclose(ptfact);
}
Gemini