2016-05-08 7 views
0

Ich versuche, einen Aufschlag Prozentsatz der $ Cent pro Meile hinzufügen, aus irgendeinem Grund ignoriert es es. Wie kann ich eine var erstellen, die ich eine ganze Zahl für Prozentsatz eingeben kann und es zu den Kosten hinzufügen?Prozent in PHP

<?php 
$PriceofgallonGas = 2.59 ; 
$precent = 50 ; 
?> 



<?php 
    function installVanFuel() { 

     global $PriceofgallonGas,$precent; 
     $TankMiles = 254; 
     $SizeofTankinGallons = 31; 
     $mpg = $TankMiles/$SizeofTankinGallons; 

     $markup = (1 + $percent/100); 
     $centsPerMile = $PriceofgallonGas/$mpg; 
     echo round($centsPerMile*$markup, 2); 
    } 
?> 
+0

befestigen Sie Ihre Wunschausgabe. –

+0

Bei '$ markup = (1 + $ percent/100);' haben Sie die Variable $ prozent falsch geschrieben. –

+0

Kraftstoffkosten = .32 cent x 50% – 847Videos

Antwort

0

Sie haben einen Schreibfehler, bitte überprüfen Sie.

Bei $markup = (1 + $percent/100); verfehlten Sie die Variable $percent.

$PriceofgallonGas = 2.59 ; 
$precent = 50 ; 

function installVanFuel() { 
    global $PriceofgallonGas, $precent; 
    $TankMiles = 254; 
    $SizeofTankinGallons = 31; 
    $mpg = $TankMiles/$SizeofTankinGallons; 

    $markup = (1 + $precent/100); 
    $centsPerMile = $PriceofgallonGas/$mpg; 
    echo round($centsPerMile*$markup, 2)." Cents x ".$precent."%"; //0.47 Cents x 50% 
} 
installVanFuel();