Gossamer Forum
Home : General : Perl Programming :

quite an easy question i believe?

Quote Reply
quite an easy question i believe?
good morning all.

I'm in the process of making a total house price calculator for my site one of which i've seen on other sites.

it's almost complet but i've come across a problem...

in real estate the agents fees change acording to the price of the house

what i need is to be able to is...
if the house price is higher than lets say $4 000 but lower than $40 000
for $price1 to equal 7

i came up with this but it don't work

elsif (($price < 4000) && ($price > 40000 ) && ($agent2 eq "ok")) {
$price1 =7;
}

can any one help?

thanks

davidd sargent
davidd@salut-france.com


Quote Reply
Re: quite an easy question i believe? In reply to
Ok,

1) Why are you using an elsif to start? Or is there an if sowhere above that you don't show?

2) With your statement you are basically saying;

if the price is less than 4,000, and greater than 40,000 and $agent2 is equal to 'ok' then do what is in the brackets.

Now, is it just me or does that not make sense? How can something be less than 4,000 and greater than 40,000???? Wink

I think you need to revise your >'s and <'s Smile

Andy

webmaster@ace-installer.com
http://www.ace-installer.com
Quote Reply
Re: quite an easy question i believe? In reply to
thanks for your reply
1) yes there is a 'if' above it's pretty much the same but lower prices
2) Sorry i tyoed in the brackets the wrong way they are the other way in the script i wrote

question: i didn't quite understand the thing about the brackets.

do i need to remove them?

Quote Reply
Re: quite an easy question i believe? In reply to
No. You don't nee to remove the bracket. All I was saying is basically how the script would look at the code, and if all 3 things matched up it would run the code inside the brackets. Also, it may help to understand what errors you are getting, and alos for you to show us a bit more of the code you have written Wink

Andy

webmaster@ace-installer.com
http://www.ace-installer.com
Quote Reply
Re: quite an easy question i believe? In reply to
Your logic is off, you're telling the interpreter to set
$price1 = 7, only if:
Code:
"The $price is less than 4,000", and "The $price is more
than 40,000". It will never be both, it can only be one or
the other. You are saying that it has to be both.
Here's your original code:
In Reply To:
elsif (($price < 4000) && ($price > 40000 ) && ($agent2 eq "ok")) {
$price1 =7;
}
Just change it to something like the following:
Code:
elsif (($price > 4000) && ($price < 40000 ) && ($agent2 eq "ok")) {
$price1 =7;
}
I think that will accomplish what you wanted. But, what
happens if the price is exactly 4,000 or 40,000? In those
cases, the $price1 variable will NOT be set to 7. To do
that, just add an equal sign (=) after the less than (<) or
greater than (>) symbol that you want.

For example to set $price1=7 when the $price is between
4,000 and 40,000, or exactly 4,000, then you would do this:

Code:
elsif (($price >= 4000) && ($price < 40000 ) && ($agent2 eq "ok")) {
$price1 =7;
}
And the same if you wanted it set when the price was at 40,000, like this: $price <= 40000

Hope that helps,

-Steven