Microsoft
Software
Hardware
Network
Question : Numeric if statment not generating desired results
Experts,
When given 2 numbers, I'd like to determine the "favorite" (for betting). The Favorite is the NEGATIVE number. So the team with a spread of "-7" is the favorite and the underdog's spread is "7".
When I output the home and visiting spreads:
echo $vis_spread . "<BR>";
echo $home_spread;
I get:
13.5
-13.5
So clearly, one is negative and one is positive, and therefore less than the other.
When I run the following if statement:
if ($home_spread<<$vis_spread
){
// Option 1
$FAV = $teamname[1];
$UDOG = $teamname[0];
$SPREAD = $home_spread;
}
elseif($vis_spread<<$home_
spread){
// Option 2
$FAV = $teamname[0];
$UDOG = $teamname[1];
$SPREAD = $vis_spread;
}
else{
// Option 3
$FAV = $teamname[1];
$UDOG = $teamname[0];
$SPREAD = '0';
// Spread of 0 means teams are EVEN.
}
}
The above statement Outputs Option 1 EVERY TIME.
In cases when Option 2 should be true, it still results in #1.
I know this is incorrect, because the $SPREAD appears as a positive number
This shouldn't be possible because the negative number should ALWAYS be less than the positive, becoming the $SPREAD.
example of incorrect result:
-3
3
Favorite: Virginia Tech
Underdog: Boise State
Spread: 3
Visiting: Boise State -3
Home: Virginia Tech 3
The Favorite should be Boise State since it's spread is -3.
It's outputting 3 as the spread, telling me it believes option 1 in the if statement is true.
Any ideas?
Answer : Numeric if statment not generating desired results
try as
$vis_spread = $spread->{"spread_visiting"
} + 0;
$home_spread = $spread->{"spread_home"} + 0;
0 addition will make sure that the variables are in integer...
Random Solutions
I need your advice in this class php
Data Encryption Software
Exchange 2003 on SBS 2003 Active Sync and Blackberry/iPhone Configuration Help Needed
Able to access the internet but unable to receive microsoft updates?
Oracle qry on system tables
Where is the Default Printer set in Crystal Reports?
window 7 OS: blank (black) screen only, as it logs in
Need to show image above datalist if user selects. the image.
Exchange 2010 Antivirus Options
added a function to webservice. Why can't i see it by intellesense on the client