53 lines
1007 B
C
53 lines
1007 B
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
# define CANETTE 0.6
|
|
# define PACK 3.39
|
|
|
|
int main(void) {
|
|
double budget;
|
|
double i;
|
|
int nb_packs, nb_canettes;
|
|
nb_packs = 0;
|
|
nb_canettes = 0;
|
|
printf("Quel est votre budget ? ");
|
|
scanf("%lf", &budget);
|
|
for (i = budget; i > PACK; i -= PACK) {
|
|
nb_packs++;
|
|
}
|
|
budget -= (nb_packs * PACK);
|
|
for (i = budget; i > CANETTE; i -= CANETTE) {
|
|
nb_canettes++;
|
|
}
|
|
if (nb_packs > 0 && nb_canettes > 0) {
|
|
if (nb_packs == 1) {
|
|
printf("1 pack et ");
|
|
}
|
|
else {
|
|
printf("%d packs et ", nb_packs);
|
|
}
|
|
if (nb_canettes == 1) {
|
|
printf("1 unité");
|
|
}
|
|
else {
|
|
printf("%d unités", nb_canettes);
|
|
}
|
|
}
|
|
else if (nb_packs > 0) {
|
|
if (nb_packs == 1){
|
|
printf("1 pack");
|
|
}
|
|
else {
|
|
printf("%d packs", nb_packs);
|
|
}
|
|
}
|
|
else {
|
|
if (nb_canettes == 1) {
|
|
printf("1 unité");
|
|
}
|
|
else {
|
|
printf("%d unités", nb_canettes);
|
|
}
|
|
}
|
|
printf("\n");
|
|
return EXIT_SUCCESS;
|
|
} |