?php
declare(strict_types = 1 );
//Crée un tableau pour stocker les prix TTC des consommations
(array)$infoconsommation = [
"café" => 0 ,
"soda" => 0 ,
"bière" => 0
];
(int)$nombrecafe= -1;
(int)$nombresoda= -1;
(int)$nombrebiere= -1;
(array)$tarif =[
"café" => 1.00,
"soda" => 2.00,
"bière" =>2.40
];
//modifier le tableau (prix) pour qu'il puissse contenir le taux de TVA .
(array)$prixConso = [
"café" => ['prixht' => 1.00, 'tva' =>0.1],
"soda" => ['prixht' => 2.00, 'tva' =>0.1],
"bière" => ['prixht' => 2.00, 'tva' =>0.2],
];
//Demander à l'utilisateur le nombre de cafés.
while($nombrecafe < 0):
print("Bonjour combien voulez-vous de café ?".PHP_EOL);
$nombrecafe =intval(trim(fgets(STDIN)));
endwhile;
$infoconsommation["café"] = $nombrecafe;
//Demander à l'utilisateur le nombre de sodas.
while($nombresoda < 0):
print("Et combien voulez-vous de sodas ?".PHP_EOL);
$nombresoda =intval(trim(fgets(STDIN)));
endwhile;
$infoconsommation["soda"] = $nombresoda;
//Demander à l'utilisateur le nombre de bieres.
while($nombrebiere < 0):
print("Et pour finir voulez-vous de bières ?".PHP_EOL);
$nombrebiere = intval(trim(fgets(STDIN)));
endwhile;
$infoconsommation["bière"] = $nombrebiere;
//Calculer total à payer.
(float)$total=0.0 ;
$total = ($nombrecafe*$prixConso["café"]["prixht"]) * (1 + $prixConso["café"]["tva"]) +
$nombrecafe*$prixConso["soda"]["prixht"] * (1 + $prixConso["soda"]["tva"]) +
$nombrecafe*$prixConso["bière"]["prixht"] * (1 + $prixConso["bière"]["tva"]);
//afficher total à payer.
printf("Le total à payer est de %g euros".PHP_EOL, $total);
//Rendu monnaie.
(float)$recumonnaie=0.0;
(float)$rendumonnaie = 0.0;
while(!$recumonnaie > 0 ):
print("Combien me donnez vous ?");
$recumonnaie = intval(trim(fgets(STDIN)));
endwhile;
$rendumonnaie = $recumonnaie - $total;
printf("Rendre %g euros au client".PHP_EOL, $rendumonnaie);
//ticket de caisse -> afficher le ticket.
(float)$totalHT = 0.0;
$totalHT = $nombrecafe*$prixConso["café"]["prixht"] +
$nombrecafe*$prixConso["soda"]["prixht"] +
$nombrecafe*$prixConso["bière"]["prixht"];
(float)$total = 0.0;
$total = ($nombrecafe*$prixConso["café"]["prixht"]) * (1 + $prixConso["café"]["tva"]) +
$nombrecafe*$prixConso["soda"]["prixht"] * (1 + $prixConso["soda"]["tva"]) +
$nombrecafe*$prixConso["bière"]["prixht"] * (1 + $prixConso["bière"]["tva"]);
print(PHP_EOL. "________________________TICKET DE CAISSE________________________ ");
printf(PHP_EOL . "%g café à %g euros HT soit %.2f TTC ".PHP_EOL, $nombrecafe,$prixConso["café"]["prixht"], ($nombrecafe*$prixConso["café"]["prixht"]) * (1 + $prixConso["café"]["tva"]) );
printf(PHP_EOL . "%g soda à %g euros HT soit %.2f TTC ".PHP_EOL, $nombresoda,$prixConso["soda"]["prixht"], ($nombresoda*$prixConso["soda"]["prixht"]) * (1 + $prixConso["soda"]["tva"]) );
printf(PHP_EOL . "%g bières à %g euros HT soit %.2f TTC ".PHP_EOL, $nombrebiere,$prixConso["bière"]["prixht"], ($nombrebiere*$prixConso["bière"]["prixht"]) * (1 + $prixConso["bière"]["tva"]) );
printf(PHP_EOL . "Total hors taxe %.2f".PHP_EOL, $totalHT) ;
printf(PHP_EOL . "Total toute taxe %.2f".PHP_EOL,$total ) ;
print(PHP_EOL. "________________________________________________________________ ".PHP_EOL);
print('Voulez vous que je vous imprime le Ticket de caisse ?');
array()
while($findejournee):
print()