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?

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($round<$maxTo5 and $round>$minTo5) return $round/$digits;
if($round<$max and $round>$min) return $round/$digits;
if($round<$maxTo5 and $round>$minTo5) return $round/$digits;
return round($num)/$digits;

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

Sponsor our Newsletter | Privacy Policy | Terms of Service