1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
#include <stdio.h>
struct options {
float ass_annul;
};
struct vol {
int num_vol;
char aero_dep[30];
char aero_des[30];
};
float calcul_prix();
struct vol tabvols[100];
float recup_prix_vol();
struct options tarif_option;
struct options taboptions[1];
main()
{
float prix_base = 50, index = 2, prix_total;
printf("recup prix \n");
/* Récupération du prix de base du numéro de vol 1111 */
prix_base = recup_prix_vol(1111)
prix_total = calcul_prix(prix_base, 2.5);
printf("prix total : %4.2f", prix_total);
}
float calcul_prix(float prix_base, float index)
{
float ass_annul, prix_supp, prix_total, prix_resa;
char bidon; // Variable de vidage du buffer
char rep;
/* ---- Calcul prix total TTC hors options ---- */
prix_total = prix_base * index;
printf("Prix TTC %4.2f", prix_total);
/* ---- Déclaration des options ---- */
printf("Déclarer des options pour ce passager ? (O/N)");
scanf("%c", rep);
if(rep == 'O')
{
FILE *ftarif;
int temp1;
/* ---- Chargement du fichier des tarifs ---- */
ftarif = fopen("tarifs_options", "r");
if(ftarif == NULL)
{
printf("Problème d'accès au fichier.\n");
}
else
{
while(!feof(ftarif))
{
temp1 = fscanf(ftarif, "%f", &tarif_option.ass_annul);
if(temp1 != EOF)
{
taboptions[0] = tarif_option;
}
}
}
fclose(ftarif);
// Assurance annulation
printf("\n\nSouscrire à une assurance annulation ? (O/N) : ");
scanf("%c", &rep);
bidon=getchar();
if (rep == 'O')
{
ass_annul=taboptions[0].ass_annul;
printf("Assurance annulation souscrite\n");
}
else
{
ass_annul=0;
printf("Assurance annulation non souscrite\n");
}
/* --- Affichage des options prises ---- */
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
printf("Assurance annulation : %-4.2f\n", ass_annul);
prix_supp = ass_annul ;
printf("\n\nMontant total, par passager, des options prises : %-4.2f", prix_supp);
}
else
{
prix_supp = 0;
printf("Aucune option choisie\n");
}
/* Renvoi du prix total par passager */
prix_resa = prix_supp + prix_total;
return prix_resa;
}
float recup_prix_vol(int numvol)
{
// Recherche dans le fichier des vols, retrouve le numéro de vol souhaité et retourne son prix
// Pour simplifier le code posté, je mets directement le résultat
prix_base = 50.00;
return tabvols[j].prix_base;
} |
Partager