Log in

View Full Version : Resolved Switch Statements problem



x0prah_Winfr3yx
01-24-2009, 09:05 PM
hello, this is my first post so thanks for reading up on it.

i'm having issues with my 1st switch statement, can you tell me what looks incorrect in my code?

what i'm trying to accomplish is getting the final total of price plus state tax per state.




<?php
$price == 20.00
$cust_state == "TX";
?>


<?php
switch ( $cust_state )
{
case "OR":
$salestax = 0.5;
break;

case "TX":
$salestax = 0.3;
break;

case "CA":
$salestax = 1;
break;

default:
$salestax = 0.1;
break;
}

$final_price = $price * $salestax;
?>

<?php echo "the final total is $final_price"; ?>



I'm getting back "the final total is 0"

Snookerman
01-24-2009, 09:31 PM
Try this:

<?php
$price = 20.00
$cust_state = "TX";
?>

Good luck!

x0prah_Winfr3yx
01-24-2009, 09:38 PM
Try this:

<?php
$price = 20.00
$cust_state = "TX";
?>

Good luck!

i'm assuming you didn't mean to leave out that first ";"

i did try your method, it was actually my first thought too, but i'm still getting back the same result.

Snookerman
01-24-2009, 10:09 PM
Try this then:

{
case "OR":
$salestax = 0.5;
break;

case "TX":
$salestax = 0.3;
break;

case "CA":
$salestax = 1;
break;

default:
$salestax = 0.1;
}

Good luck!

x0prah_Winfr3yx
01-25-2009, 04:58 AM
thank you, i realize that i was mistyping a variable. wonder how many times that happens?

thanks for your help

Snookerman
01-25-2009, 10:37 AM
You're welcome, glad to help!

I'd like to recommend Notepad++ (http://notepad-plus.sourceforge.net/) since it has a nice feature that highlights all instances of a word or variable when you mark it which is really helpful when checking for typos.

You can go to your first post in this thread, click http://www.dynamicdrive.com/forums/images/buttons/edit.gif then click Go Advanced and add the Resolved prefix to the thread title. This will let other users know the problem has been solved.

Good luck with your site!