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 114 115 116 117 118
|
#include<stdio.h>
#include <stdbool.h>
int nbSpec;
int specSelect = 9999;
struct spectacle {
char intitule[50];
int nbPlaces;
};
struct spectacle tabSpectacles[10];
void init()
{
struct spectacle tabTemp[] = {
{"En attendant Godot", 10},
{"Tant qu'il y aura des pommes", 4},
{"Le cercle des poètes disparus", 7},
{"L'inspecteur a ri", 9},
};
for(int i=0;i < sizeof(tabTemp) / sizeof(tabTemp[0]); i++) {
tabSpectacles[i] = tabTemp[i];
}
nbSpec = sizeof(tabTemp) / sizeof(tabTemp[0]);
}
void afficher()
{
printf("Liste des spectacles :\n");
for (int i = 0; i < nbSpec;i++) {
printf("%d - %s (%d places)\n", i, tabSpectacles[i].intitule, tabSpectacles[i].nbPlaces);
}
}
bool quantiteEstDisponible(int idSpectacle, int quantiteDemandee)
{
int quantiteDisponible = tabSpectacles[idSpectacle].nbPlaces;
return quantiteDemandee <= quantiteDisponible;
}
bool retirerPlace(int idSpectacle, int quantiteDemandee)
{
if (quantiteEstDisponible(idSpectacle, quantiteDemandee)) {
tabSpectacles[idSpectacle].nbPlaces -= quantiteDemandee;
return true;
} else {
return false;
}
}
void ajouterPlaces(int idSpectacle, int quantiteDemandee)
{
tabSpectacles[idSpectacle].nbPlaces += quantiteDemandee;
}
int menu(){
int choix;
printf("Menu \n");
if(specSelect != 9999) {
printf("Spectacleselectionne: %i %s %i \n", specSelect, tabSpectacles[specSelect].intitule, tabSpectacles[specSelect].nbPlaces);
}
else
{
printf("Pas de spectacles selectionné \n");
printf("1 selectionner un spectacle \n");
printf("2 Afficher les spectacles \n");
}
if(specSelect != 9999) {
printf("3 Réserver des places \n");
printf("4 Ajouter des places \n");
printf("\n 0 Quitter \n");
}
printf("Entrez votre choix \n");
scanf("%d", &choix);
return choix;
}
int main(int argc, char** argv)
{
//init();
//afficher();
//printf("Retirer place spec 3, 3 places \n");
//printf("Réponse : %i \n", retirerPlace(3, 01));
//afficher();
//printf("Retirer place spec 3, 3 places \n");
//printf("Réponse : %i \n", retirerPlace(3, 11));
//afficher();
//ajouterPlaces(3, 10);
//afficher();
int choix = 99;
while(choix != 0) {
choix = menu();
printf("Votre choix %i \n", choix);
}
return 0;
} |
Partager