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
Itunes could not connect to the Itunes Store. The network connection timed out.
Delivery not authorized, message refused. 550-5.7.1 Message targeted to organization's federated delivery mailbox.
New install of SBS 2008 continuously downloads 2.5GB per day (WSUS disabled)
subquery returned more than 1 value: database vendor code 512
Php 500 internal server error received on website but not using xampp at home
Access VBA to stop all macros
SSH console: go to specified folder after login
Invalid object reference error
Shadowing/Overriding in C#
Filtering the SSRS report based on multivalue multiple parameters passed to stored procedure