some funny modifications

Signed-off-by: Mathéo Hersan <matheohersan@MacBook-Pro-de-Matheo.local>
pull/13/head
Mathéo Hersan 1 year ago
parent d11e02344b
commit c2d1e3da99
No known key found for this signature in database
GPG Key ID: 4EF19C64D78EC91B

BIN
app

Binary file not shown.

@ -1,4 +1,4 @@
32 4.20 1 32 36.40 1
660 5639.20 0 660 5419.20 0
5079 75.50 0 5079 75.50 0
53 0.00 0 53 0.00 0

@ -84,7 +84,7 @@ void supprimer_article(int tPanier[], int tQuantite[], int *tLogPanier, int refe
void verifInt(int *var) { void verifInt(int *var) {
while (scanf("%d", var) != 1 || *var < 0) { while (scanf("%d", var) != 1 || *var < 0) {
fprintf(stderr, "Erreur de saisie, veuillez recommencer : "); fprintf(stderr, "\x1B[31mERREUR : Veuillez entrer une valeur valide (entier positif) :\x1B[0m ");
while (getchar() != '\n'); while (getchar() != '\n');
} }
while (getchar() != '\n'); while (getchar() != '\n');
@ -92,8 +92,8 @@ void verifInt(int *var) {
void verifFloat(float *var) { void verifFloat(float *var) {
while (scanf("%f", var) != 1 || *var < -1) { while (scanf("%f", var) != 1 || *var < -0) {
while (getchar() != '\n'); while (getchar() != '\n');
fprintf(stderr, "ERREUR : Veuillez entrer une valeur valide (entier positif) : "); fprintf(stderr, "\x1B[31mERREUR : Veuillez entrer une valeur valide (valeur positive) :\x1B[0m ");
} }
} }

@ -35,7 +35,7 @@ void ajouter_article_au_panier(int numClient, int tRef[], float tPoids[], float
articleIndex = trouver_index_article(reference, tRef, tLogArticle); articleIndex = trouver_index_article(reference, tRef, tLogArticle);
while (articleIndex == -1) { while (articleIndex == -1) {
printf("ERREUR : Article non trouvé. Veuillez entrer une référence valide : "); fprintf(stderr, "\x1B[31mERREUR : Article non trouvé. Veuillez entrer une référence valide :\x1B[0m ");
verifInt(&reference); verifInt(&reference);
articleIndex = trouver_index_article(reference, tRef, tLogArticle); articleIndex = trouver_index_article(reference, tRef, tLogArticle);
} }
@ -44,9 +44,9 @@ void ajouter_article_au_panier(int numClient, int tRef[], float tPoids[], float
verifInt(&quantite); verifInt(&quantite);
poidsTotal = tPoids[articleIndex] * quantite; poidsTotal = tPoids[articleIndex] * (float)quantite;
volumeTotal = tVol[articleIndex] * quantite; volumeTotal = tVol[articleIndex] * (float)quantite;
montantTotal = tPrixUnitaire[articleIndex] * quantite; montantTotal = tPrixUnitaire[articleIndex] * (float)quantite;
if (poidsTotal > chargeMaximale) { if (poidsTotal > chargeMaximale) {
depassementCharge = poidsTotal - chargeMaximale; depassementCharge = poidsTotal - chargeMaximale;
@ -60,7 +60,7 @@ void ajouter_article_au_panier(int numClient, int tRef[], float tPoids[], float
depassementBudget = montantTotal - budget; depassementBudget = montantTotal - budget;
} }
montantTotal = tPrixUnitaire[articleIndex] * quantite; montantTotal = tPrixUnitaire[articleIndex] * (float)quantite;
clientIndex = trouver_index_client(numClient, tNumClient, tLogClient); clientIndex = trouver_index_client(numClient, tNumClient, tLogClient);
@ -108,14 +108,14 @@ void supprimer_article_du_panier(int tPanier[], int tQuantite[], int *tLogPanier
articleIndex = trouver_index_article(reference, tPanier, *tLogPanier); articleIndex = trouver_index_article(reference, tPanier, *tLogPanier);
while (articleIndex == -1) { while (articleIndex == -1) {
printf("Article non trouvé dans le panier. Veuillez entrer une référence valide : "); fprintf(stderr, "\x1B[31mERREUR : Article non trouvé dans le panier. Veuillez entrer une référence valide :\x1B[0m ");
verifInt(&reference); verifInt(&reference);
articleIndex = trouver_index_article(reference, tPanier, *tLogPanier); articleIndex = trouver_index_article(reference, tPanier, *tLogPanier);
} }
supprimer_article(tPanier, tQuantite, tLogPanier, reference, numClient, tNumClient, tLogClient, tRef, tPrixUnitaire, tCagnotte); supprimer_article(tPanier, tQuantite, tLogPanier, reference, numClient, tNumClient, tLogClient, tRef, tPrixUnitaire, tCagnotte);
printf("Article supprimé du panier avec succès.\n"); printf("\033[32mArticle supprimé du panier avec succès.\033[0m\n");
} }
@ -127,12 +127,6 @@ void affiche_recap_panier(int tPanier[], int tLogPanier, int tRef[], float tPoid
float poidsTotal = 0, volumeTotal = 0, montantTotal = 0, prixArticle = 0, poidsArticle = 0, volumeArticle = 0; float poidsTotal = 0, volumeTotal = 0, montantTotal = 0, prixArticle = 0, poidsArticle = 0, volumeArticle = 0;
char attentionDepassement[200] = ""; char attentionDepassement[200] = "";
printf("Contenu du panier : ");
for (int i = 0; i < tLogPanier; i++) {
printf("%d ", tPanier[i]);
}
printf("\n");
printf("Récap :\n"); printf("Récap :\n");
printf("Réf Qté Poids Vol PrixU PoidsTot VolTot PrixTot\n"); printf("Réf Qté Poids Vol PrixU PoidsTot VolTot PrixTot\n");
@ -147,7 +141,7 @@ void affiche_recap_panier(int tPanier[], int tLogPanier, int tRef[], float tPoid
printf("%d\t %d\t %.2f\t %.2f\t %.2f\t %.2f\t %.2f\t %.2f\n", printf("%d\t %d\t %.2f\t %.2f\t %.2f\t %.2f\t %.2f\t %.2f\n",
reference, quantite, poidsArticle, volumeArticle, reference, quantite, poidsArticle, volumeArticle,
prixArticle, poidsArticle * quantite, volumeArticle * quantite, prixArticle * quantite); prixArticle, poidsArticle * (float)quantite, volumeArticle * (float)quantite, prixArticle * (float)quantite);
poidsTotal += poidsArticle * (float)quantite; poidsTotal += poidsArticle * (float)quantite;
volumeTotal += volumeArticle * (float)quantite; volumeTotal += volumeArticle * (float)quantite;
@ -181,12 +175,13 @@ void affiche_recap_panier(int tPanier[], int tLogPanier, int tRef[], float tPoid
printf("Charge Actuelle: %.2f kg\n", poidsTotal); printf("Charge Actuelle: %.2f kg\n", poidsTotal);
if (strlen(attentionDepassement) > 0) { if (strlen(attentionDepassement) > 0) {
printf("Attention : %s", attentionDepassement); printf("Attention : \n");
printf("%s", attentionDepassement);
} }
} }
void configurer_session_client(int tNumClient[], int tLogClient, double *budget, float *volumeCoffre, float *chargeMaximale, int *numClient) { void configurer_session_client(int tNumClient[], int tLogClient, double *budget, float *volumeCoffre, float *chargeMaximale, int *numClient) {
int indexClient, choixBudget = 0, choix; int indexClient, choixBudget = 0;
printf("Veuillez saisir votre numéro de client : "); printf("Veuillez saisir votre numéro de client : ");
verifInt(numClient); verifInt(numClient);
@ -195,7 +190,7 @@ void configurer_session_client(int tNumClient[], int tLogClient, double *budget,
indexClient = trouver_index_client(*numClient, tNumClient, tLogClient); indexClient = trouver_index_client(*numClient, tNumClient, tLogClient);
while (indexClient == -1) { while (indexClient == -1) {
printf("ERREUR : Veuillez entrer un numéro de client valide : "); fprintf(stderr, "\x1B[31mERREUR : Veuillez entrer un numéro de client valide :\x1B[0m ");
verifInt(numClient); verifInt(numClient);
indexClient = trouver_index_client(*numClient, tNumClient, tLogClient); indexClient = trouver_index_client(*numClient, tNumClient, tLogClient);
} }
@ -204,14 +199,14 @@ void configurer_session_client(int tNumClient[], int tLogClient, double *budget,
printf("Voulez-vous définir un budget à ne pas dépasser ? (1 pour Oui, 0 pour Non) : "); printf("Voulez-vous définir un budget à ne pas dépasser ? (1 pour Oui, 0 pour Non) : ");
while (scanf("%d", &choixBudget) != 1 || (choixBudget != 0 && choixBudget != 1)) { while (scanf("%d", &choixBudget) != 1 || (choixBudget != 0 && choixBudget != 1)) {
while (getchar() != '\n'); while (getchar() != '\n');
printf("ERREUR : Veuillez entrer 1 pour Oui ou 0 pour Non : "); fprintf(stderr, "\x1B[31mERREUR : Veuillez entrer 1 pour Oui ou 0 pour Non :\x1B[0m ");
} }
if (choixBudget == 1) { if (choixBudget == 1) {
printf("Entrez le budget à ne pas dépasser : "); printf("Entrez le budget à ne pas dépasser : ");
while (scanf("%lf", budget) != 1 || *budget <= 0) { while (scanf("%lf", budget) != 1 || *budget <= 0) {
while (getchar() != '\n'); while (getchar() != '\n');
printf("ERREUR : Veuillez entrer un budget valide (nombre positif) : "); fprintf(stderr, "\x1B[31mERREUR : Veuillez entrer un budget valide (nombre positif) :\x1B[0m ");
} }
} }
@ -233,7 +228,7 @@ void modifier_quantite_article_panier(int tPanier[], int tQuantite[], int *tLogP
articleIndex = trouver_index_article(reference, tPanier, *tLogPanier); articleIndex = trouver_index_article(reference, tPanier, *tLogPanier);
while (articleIndex == -1) { while (articleIndex == -1) {
printf("Article non trouvé dans le panier. Veuillez entrer une référence valide : "); fprintf(stderr, "\x1B[31mERREUR : Article non trouvé dans le panier. Veuillez entrer une référence valide :\x1B[0m ");
verifInt(&reference); verifInt(&reference);
articleIndex = trouver_index_article(reference, tPanier, *tLogPanier); articleIndex = trouver_index_article(reference, tPanier, *tLogPanier);
} }
@ -249,7 +244,7 @@ void modifier_quantite_article_panier(int tPanier[], int tQuantite[], int *tLogP
tQuantite[articleIndex] = quantite; tQuantite[articleIndex] = quantite;
printf("Quantité modifiée avec succès.\n"); printf("\033[32mQuantité modifiée avec succès.\033[0m\n");
} }
void reinitialiser_panier(int tPanier[], int tQuantite[], int *tLogPanier, float tCagnotte[], int numClient, int tNumClient[], int tLogClient, int tRef[], float tPrixUnitaire[]) { void reinitialiser_panier(int tPanier[], int tQuantite[], int *tLogPanier, float tCagnotte[], int numClient, int tNumClient[], int tLogClient, int tRef[], float tPrixUnitaire[]) {
@ -257,26 +252,28 @@ void reinitialiser_panier(int tPanier[], int tQuantite[], int *tLogPanier, float
supprimer_article(tPanier, tQuantite, tLogPanier, tPanier[i], numClient, tNumClient, tLogClient, tRef, tPrixUnitaire, tCagnotte); supprimer_article(tPanier, tQuantite, tLogPanier, tPanier[i], numClient, tNumClient, tLogClient, tRef, tPrixUnitaire, tCagnotte);
} }
*tLogPanier = 0; *tLogPanier = 0;
printf("\033[32mLe panier a été réinitialisé avec succès.\033[0m\n");
} }
void deduire_cagnotte(int numClient, float montant, int tNumClient[], float tCagnotte[], int tLogClient, int tSus[]) { void deduire_cagnotte(int numClient, float montant, int tNumClient[], float tCagnotte[], int tLogClient) {
int clientIndex; int clientIndex;
clientIndex = trouver_index_client(numClient, tNumClient, tLogClient); clientIndex = trouver_index_client(numClient, tNumClient, tLogClient);
if (clientIndex == -1) { if (clientIndex == -1) {
printf("Client non trouvé. Impossible de déduire la cagnotte.\n"); fprintf(stderr, "\x1B[31mERREUR : Client non trouvé. Impossible de déduire la cagnotte.\x1B[0m\n ");
return; return;
} }
if (tCagnotte[clientIndex] < montant) { if (tCagnotte[clientIndex] < montant) {
printf("Cagnotte insuffisante. Impossible de déduire la cagnotte.\n"); fprintf(stderr, "\x1B[31mERREUR : Cagnotte insuffisante. Impossible de déduire la cagnotte.\x1B[0m\n ");
return; return;
} }
tCagnotte[clientIndex] -= montant; tCagnotte[clientIndex] -= montant;
printf("Montant déduit de la cagnotte avec succès.\n"); printf("\033[32mMontant déduit de la cagnotte avec succès.\033[0m\n");
printf("Il vous reste %.2f euros dans votre cagnotte.\n", tCagnotte[clientIndex]);
} }
void quitter_application(int tPanier[], int tLogPanier, int tRef[], float tPoid[], float tVol[], void quitter_application(int tPanier[], int tLogPanier, int tRef[], float tPoid[], float tVol[],
@ -294,7 +291,7 @@ void quitter_application(int tPanier[], int tLogPanier, int tRef[], float tPoid[
prixArticle = tPrixUnitaire[articleIndex]; prixArticle = tPrixUnitaire[articleIndex];
quantite = tQuantite[i]; quantite = tQuantite[i];
montantTotal += prixArticle * quantite; montantTotal += prixArticle * (float)quantite;
if (budget > 0 && montantTotal > budget) { if (budget > 0 && montantTotal > budget) {
depassement = montantTotal - budget; depassement = montantTotal - budget;
@ -312,7 +309,14 @@ void quitter_application(int tPanier[], int tLogPanier, int tRef[], float tPoid[
printf("Budget : %.2f euros\n", budget); printf("Budget : %.2f euros\n", budget);
} }
if(tSus[clientIndex] == 1) { if(tSus[clientIndex] == 1 && budget > 0 && montantTotal > budget) {
printf("Attention : %s", attentionDepassement);
printf("Vous ne pourrez pas payer. De plus vous ne pourrez pas utiliser votre cagnotte car votre carte est suspendu.\n");
printf("Payement non effectué.\n");
return;
}
if(tSus[clientIndex] == 1 && budget > 0 && montantTotal < budget) {
printf("Vous ne pourrez pas utiliser votre cagnotte car votre carte est suspendu.\n"); printf("Vous ne pourrez pas utiliser votre cagnotte car votre carte est suspendu.\n");
return; return;
} }
@ -324,17 +328,15 @@ void quitter_application(int tPanier[], int tLogPanier, int tRef[], float tPoid[
if (budget > 0 && montantTotal > budget && tCagnotte[clientIndex] < (montantTotal - budget)) { if (budget > 0 && montantTotal > budget && tCagnotte[clientIndex] < (montantTotal - budget)) {
printf("Attention : %s", attentionDepassement); printf("Attention : %s", attentionDepassement);
printf("Vous ne pourrez pas payer. De plus vous n'avez pas assez dans votre cagnotte pour la déduire et payer\n"); printf("Vous ne pourrez pas payer. De plus vous n'avez pas assez dans votre cagnotte pour la déduire et payer\n");
printf("Montant de votre cagnotte %.2f\n", tCagnotte[clientIndex]);
} }
if (budget > 0 && montantTotal > budget && montantTotal < budget + tCagnotte[clientIndex]) { if (budget > 0 && montantTotal > budget && montantTotal < budget + tCagnotte[clientIndex]) {
printf("Attention : %s", attentionDepassement); printf("Attention : %s", attentionDepassement);
printf("Vous ne pourrez pas payer, mais vous avez suffisamment dans votre cagnotte pour payer.\n"); printf("Vous ne pourrez pas payer, mais vous avez suffisamment dans votre cagnotte pour déduire le prix.\n");
printf("Montant de votre cagnotte %.2f\n", tCagnotte[clientIndex]);
printf("Voulez-vous déduire de votre cagnotte avant de quitter ? (1 pour Oui, 0 pour Non) : "); printf("Voulez-vous déduire de votre cagnotte avant de quitter ? (1 pour Oui, 0 pour Non) : ");
while (scanf("%d", &choixCagnotte) != 1 || (choixCagnotte != 0 && choixCagnotte != 1)) { while (scanf("%d", &choixCagnotte) != 1 || (choixCagnotte != 0 && choixCagnotte != 1)) {
while (getchar() != '\n'); while (getchar() != '\n');
printf("ERREUR : Veuillez entrer 1 pour Oui ou 0 pour Non : "); fprintf(stderr, "\x1B[31mERREUR : Veuillez entrer 1 pour Oui ou 0 pour Non :\x1B[0m ");
} }
if (choixCagnotte == 1) { if (choixCagnotte == 1) {
@ -342,28 +344,29 @@ void quitter_application(int tPanier[], int tLogPanier, int tRef[], float tPoid[
verifFloat(&montantDeduction); verifFloat(&montantDeduction);
while (montantDeduction < (montantTotal - budget)) { while (montantDeduction < (montantTotal - budget)) {
printf("ERREUR : Vous devez déduire suffisamment pour payer l'intégralité du montant dû.\n"); fprintf(stderr, "\x1B[31mERREUR : Vous devez déduire suffisamment pour payer l'intégralité du montant dû.\x1B[0m\n");
printf("Montant minimum à déduire pour payer : %.2f\n", montantTotal - budget); printf("Montant minimum à déduire pour payer : %.2f\n", montantTotal - budget);
printf("Entrez le montant à déduire de votre cagnotte : "); printf("Entrez le montant à déduire de votre cagnotte : ");
verifFloat(&montantDeduction); verifFloat(&montantDeduction);
} }
deduire_cagnotte(numClient, montantDeduction, tNumClient, tCagnotte, tLogClient);
deduire_cagnotte(numClient, montantDeduction, tNumClient, tCagnotte, tLogClient, tSus); return;
printf("Il vous reste %.2f euros dans votre cagnotte.\n", tCagnotte[clientIndex]); } else {
printf("Payement non effectué.\n");
return;
} }
} }
printf("Voulez-vous déduire de votre cagnotte avant de quitter ? (1 pour Oui, 0 pour Non) : "); printf("Voulez-vous déduire de votre cagnotte avant de quitter ? (1 pour Oui, 0 pour Non) : ");
while (scanf("%d", &choixCagnotte) != 1 || (choixCagnotte != 0 && choixCagnotte != 1)) { while (scanf("%d", &choixCagnotte) != 1 || (choixCagnotte != 0 && choixCagnotte != 1)) {
while (getchar() != '\n'); while (getchar() != '\n');
printf("ERREUR : Veuillez entrer 1 pour Oui ou 0 pour Non : "); fprintf(stderr, "\x1B[31mERREUR : Veuillez entrer 1 pour Oui ou 0 pour Non :\x1B[0m ");
} }
if (choixCagnotte == 1) { if (choixCagnotte == 1) {
printf("Entrez le montant à déduire de votre cagnotte : "); printf("Entrez le montant à déduire de votre cagnotte : ");
verifFloat(&montantDeduction); verifFloat(&montantDeduction);
deduire_cagnotte(numClient, montantDeduction, tNumClient, tCagnotte, tLogClient, tSus); deduire_cagnotte(numClient, montantDeduction, tNumClient, tCagnotte, tLogClient);
printf("Il vous reste %.2f euros dans votre cagnotte.\n", tCagnotte[clientIndex]);
} }
} }
@ -372,7 +375,7 @@ void menu_client(int *choix) {
printf("Vous choisissez: "); printf("Vous choisissez: ");
while (scanf("%d", choix) != 1 || *choix < 0 || *choix > 9 || (*choix > 6 && *choix < 9)) { while (scanf("%d", choix) != 1 || *choix < 0 || *choix > 9 || (*choix > 6 && *choix < 9)) {
while (getchar() != '\n'); while (getchar() != '\n');
printf("ERREUR : Veuillez entrer un choix valide : "); fprintf(stderr, "\x1B[31mERREUR : Veuillez entrer un choix valide :\x1B[0m ");
} }
} }
@ -414,7 +417,6 @@ void global_client(void) {
break; break;
case 6: case 6:
reinitialiser_panier(tPanier, tQuantite, &tLogPanier, tCagnotte, numClient, tNumClient, tLogClient, tRef, tPrixUnitaire); reinitialiser_panier(tPanier, tQuantite, &tLogPanier, tCagnotte, numClient, tNumClient, tLogClient, tRef, tPrixUnitaire);
printf("Le panier a été réinitialisé.\n");
break; break;
case 9: case 9:
quitter_application(tPanier, tLogPanier, tRef, tPoids, tVol, tPrixUnitaire, tQuantite, tCagnotte, numClient, tNumClient, tLogClient, budget, tSus); quitter_application(tPanier, tLogPanier, tRef, tPoids, tVol, tPrixUnitaire, tQuantite, tCagnotte, numClient, tNumClient, tLogClient, budget, tSus);

@ -134,7 +134,7 @@ void reinitialiser_panier(int tPanier[], int tQuantite[], int *tLogPanier, float
* @param tLogClient - Le nombre total de clients. * @param tLogClient - Le nombre total de clients.
* @param tSus - Un tableau d'état des clients suspendus. * @param tSus - Un tableau d'état des clients suspendus.
*/ */
void deduire_cagnotte(int numClient, float montant, int tNumClient[], float tCagnotte[], int tLogClient, int tSus[]); void deduire_cagnotte(int numClient, float montant, int tNumClient[], float tCagnotte[], int tLogClient);
/** /**
* @brief Quitter l'application client. * @brief Quitter l'application client.

Loading…
Cancel
Save