help calculator

i need help making the tip rate work. so it doesnt only do the 15% but whatever percent you choose

if (array_key_exists(‘Calculate’,$_POST)){
// for the first exercise
$userBill = $_POST[‘bill’];
if (is_numeric($userBill)) {
$suggestedTip = calTip($userBill);
$output = “The suggested tip is $suggestedTip”;
} else {
$output = “Please type in your bill amount, numbers only.”;
}
}

function calTip($bill){
	$tip = $bill * 0.15; 
	return $tip;
}

Tip Calculator

What is the amount of the bill? $
What is the tip rate? %
<?php echo "
"; echo $output; ?>

i would think i could put

$tip = $bill * $tipRate??

but then i get The suggested tip is 0 everytime

wehere do u get the billrate from?

btw:
a little function u that would be userfull:
[php]// makes nice to view nums within the range given by $error
// e.g. 314 -> 300, 321 -> 320, 344 -> 350 …
function roundnice($num,$digits=0,$error=.05,$errorTo5=NULL)
{
if($errorTo5===NULL)$errorTo5=$error/2;
$digits=pow(10,$digits);
$num*=$digits;
$max=$num*(1+$error);
$min=$num*(1-$error);
$maxTo5=$num*(1+$errorTo5);
$minTo5=$num*(1-$errorTo5);
$len=1;
while($num>=pow(10,$len))$len++;

for($i=$len-1;$i>0;$i–)
{
$round=round($num/pow(10,$i)/5)*pow(10,$i)*5;
if($round<$maxTo5 and $round>$minTo5) return $round/$digits;
$round=round($num/pow(10,$i))*pow(10,$i);
if($round<$max and $round>$min) return $round/$digits;
}
$round=round($num/pow(10,$i)/5)*pow(10,$i)*5;
if($round<$maxTo5 and $round>$minTo5) return $round/$digits;
return round($num)/$digits;
}
[/php]

so it woun’t return numbers like 2,99 but 3,00 instead

Sponsor our Newsletter | Privacy Policy | Terms of Service