Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.00 KB | None | 0 0
  1. <html>
  2.    <body>
  3.      <h2>Calulateur d'essence/diesel</h2>
  4.      <title>Calulateur d'essence/diesel</title>
  5.       <form action = "<?php $_PHP_SELF ?>" method = "GET">
  6.          <br>Prix total: <input type = "text" name = "PrixTotal" /></br>
  7.          <br>Prix par litre: <input type = "text" name = "PrixLitre" /></br>
  8.          <br>Kilomètre de base (laisser à 0 si vous connaisser le nombre de Kilomètre): <input type = "text" name = "KMmin" value="0"/></br>
  9.          <br>Kilomètre total ou kilomètre parcourus: <input type = "text" name = "KMmax" /></br>
  10.          <br><input type = "submit" /></br>
  11.       </form>
  12.       <br></br>
  13.    </body>
  14. </html>
  15. <?php
  16.  
  17. //Déclaration de variable
  18.  
  19. $PrixTotal = 0;
  20. $PrixLitre = 0;
  21. $PrixKM = 0;
  22. $ConsomationMoyenneAu100 = 0;
  23. $KMmax = 0;
  24. $KMmin = 0;
  25. $KMTotal = 0;
  26. $UnLitreKM = 0;
  27. $UnKMLitre = 0;
  28. $Litre = 0;
  29.  
  30. //Récuperation depuis les champs input
  31.  
  32. $PrixTotal = $_GET["PrixTotal"];
  33. $PrixLitre = $_GET["PrixLitre"];
  34. $KMmin = $_GET["KMmin"];
  35. $KMmax = $_GET["KMmax"];
  36.  
  37. //Fonctions
  38.  
  39. function KMTotal($KMmax, $KMmin)
  40. {
  41.   if ($KMmin == 0)
  42.   {
  43.     $KMTotal = $KMmax;
  44.   }
  45.   else
  46.   {
  47.     $KMTotal = $KMmax-$KMmin;
  48.   }
  49.   return $KMTotal;
  50. }
  51.  
  52. function Litre($PrixTotal, $PrixLitre)
  53. {
  54.   $Litre = $PrixTotal/$PrixLitre;
  55.   return $Litre;
  56. }
  57.  
  58. function ConsomationMoyenneAu100($Litre, $KMTotal)
  59. {
  60.   $ConsomationMoyenneAu100 = $Litre*100/$KMTotal;
  61.   return $ConsomationMoyenneAu100;
  62. }
  63.  
  64. function UnLitreKM($KMTotal, $Litre)
  65. {
  66.   $UnKMLitre = $KMTotal/$Litre;
  67.   return $UnKMLitre;
  68. }
  69.  
  70. function PrixKM($KMTotal, $PrixTotal)
  71. {
  72.   $PrixKM = $PrixTotal/$KMTotal;
  73.   return $PrixKM;
  74. }
  75.  
  76. function UnKMLitre($Litre, $KMTotal)
  77. {
  78.   $UnKMLitre = $Litre/$KMTotal;
  79.   return $UnKMLitre;
  80. }
  81.  
  82. //Appele de Fonctions
  83.  
  84. $KMTotal = KMTotal($KMmax, $KMmin);
  85. $PrixKM = PrixKM($KMTotal, $PrixTotal);
  86. $Litre = Litre($PrixTotal, $PrixLitre);
  87. $ConsomationMoyenneAu100 = ConsomationMoyenneAu100($Litre, $KMTotal);
  88. $UnLitreKM = UnLitreKM($KMTotal, $Litre);
  89. $UnKMLitre = UnKMLitre($Litre, $KMTotal);
  90.  
  91. //Controle des champs et affiche si ils sont tous rempli
  92.  
  93. if ($PrixTotal == null)
  94. {
  95.   echo "Veuillez entrer quelque chose dans le champ Prix total";
  96. }
  97. elseif ($PrixLitre == null)
  98. {
  99.   echo "Veuillez entrer quelque chose dans le champ Prix par litre";
  100. }
  101. elseif ($KMmin == null)
  102. {
  103.   echo "Veuillez entrer quelque chose dans le champ Kilomètre de base ou mettez 0";
  104. }
  105. elseif ($KMmax == null)
  106. {
  107.   echo "Veuillez entrer quelque chose dans le champ Kilomètre total ou kilomètre parcourus";
  108. }
  109. else
  110. {
  111.   echo "<h3>Résultat</h3>";
  112.   echo "<br>En payant $PrixTotal CHF a $PrixLitre CHF le litre vous avez parcourus $KMTotal KM </br>";
  113.   echo "<br>Prix par Kilomètre parcourus : $PrixKM CHF </br>";
  114.   echo "<br>Consomation moyenne pour 100 KM : $ConsomationMoyenneAu100 L </br>";
  115.   echo "<br>Nombre de litres consommer : $Litre L </br>";
  116.   echo "<br>Nombre de kilomètre parcourus par litre : $UnLitreKM KM </br>";
  117.   echo "<br>Litre consomer par Kilomètre $UnKMLitre L </br>";
  118. }
  119. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement