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
Motherboard driver CD for HCL - P5GD2-TVM/GB/SI
OpenOffice 3.2 GPO Install Problem
OCS 2007 R2 and Cisco call manager
Terminal server 2008 R2 Pinned Taskbar Links
Automatically Adding Text to Cells
Office communicator user script
Help using .delay
How to stablish a proper setup in MS Outlook 2003 encrypting mails
Intel(R) Celeron(R) D CPU 3.06GHz on a Linux machine
MS BI sample project