Personnellement, je verrais bien un tableau à trois dimensions pour stocker tes prix :
int prix[2][2][2] = {7,8,8,8,8,9,8,7};
Puis utiliser simplement le fait qu'une expression logique retourne 0 si faux et 1 si vrai donc :
int prixAPayer = prix[condition1][condition2][condition3];
Sinon tu peux enchainer les if :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| if(condition1)
{
if(condition2)
{
}
else
{
}
}
else
{
if(condition2)
{
}
else
{
}
} |
Mais dans cette seconde solution, je vois mal comment factoriser du code vu qu'il ne semble pas y avoir de "liens" entre les différents tarif du type :
tarifEnfant = 1,5*tarifAdulte + 5;
Partager