Page 1 of 1

script not returning correct results

Posted: Mon Oct 14, 2002 10:46 am
by martincrumlish
Hi,

I am working on a script to calculate returns on bets. This involves entering odds, stake etc. The problem I am having is with adding a new element into the calculation. In betting their is something called a Rule 4. This occurs in some races and diminsihes the retrun but there is no need to go into details.

Basically, here is how it works: There is a race with odds of 2/1 and a rule 4 of 20 cents is in place. With the betting rules this means that the odds must be multiplied by 1 - rule 4. In this case the rule 4 is .20 so 1 - .20 = .80 You now have to mulpiply the odds by .80 We only multiply the first number os in the case that is 2 (for a 5/1 bet it would be 5 etc)

.80 * 2 = 1.6 is the correct answer. This calculates ok in part of my script but when it gets to the second part on the same page it is returning 1.28 instead.

Here is the form code (from a function):

Code: Select all

function print_row($bet,$number)
{
    echo "<table class=inputtable>\n<tr>\n<td align=left class=title>\n<b>$bet</b>\n</td>\n<td align=left 
class=title>\n<b>Odds</b>\n</td>\n<td align=left class=deadheat>\n<b>D.H.<font 
size=1>*</font></b>\n</td>\n</tr>";
for( $x = 1; $x < $number; $x++ ) {
    echo "<tr>\n<td align=left class=oddstext>\nSelection 
$x:</td>\n";
    echo "<td align=left class=oddsform>";
    echo "<INPUT TYPE=text class=input1 NAME=odds$x SIZE=4> / <INPUT TYPE=text class=input1 NAME=odds$x"."a 
SIZE=2></td>";
    echo "<td class=deadheatform>";
    echo "<select name=deadheat$x>\n<option></option>\n<option 
value=2>2</option>\n<option value=3>3</option>\n
<option 
value=4>4</option>\n<option value=5>5</option>\n
<option value=6>6</option>\n</select>";
    echo "</td>\n<td align=left class=oddsform>\n
<INPUT 
TYPE=text class=input1 NAME=rf$x SIZE=4>";
    echo "</tr>\n";
}
echo "<tr>\n<td align=left class=staketext>\nStake:</td>\n<td align=left class=stakeform>\n
<INPUT TYPE=text class=input1 NAME=stake SIZE=4>\n</td>\n</tr>\n";
echo "<tr>\n<td align=left colspan=2>\n<INPUT TYPE=submit NAME=submit VALUE=calculate>\n
<br>\n<font size=1>(* D.H. = Dead Heat)</font></td>\n</tr>\n</table>\n";
}
Here is the calculation and results code:

Code: Select all

<?
if($calc == "Single")
{

    if($rf1){$odds1 = $odds1 * (1 - $rf1);}
    $total = ($odds1/$odds1a * $stake) + $stake;
    if($deadheat1){$total = $total / $deadheat1;}
    
?>

<!-- results of your bet -->

<table align="left" class="resultstable">
<tr>
<td align="left" class="price">
<b>Price 1</b>
</td>
<td align="left" class="price2">
<?=$odds1."/".$odds1a?>
</td>
</tr>
<tr>
<td align="left" class="stake">
<b>Stake:</b>
</td>
<td class="stake2">
€<?=$stake?>
</td>
</tr>
<?
    }
The foprm is called from another part of the page with

Code: Select all

print_row(Single,1)
I have posted this on other forums but nobody seems to be able to help me. I am really stuck so any help is appreciated.

I have the entire script in a zip file if anyone wants to see it.

Regards,
Martin

Posted: Mon Oct 14, 2002 11:48 am
by Coco
well since 1.6 * 0.8 is 1.28, i can only assume that you have somehow doubled up your rf1 process... cant see where in the script itself, but prehaps that will help you find it

double calculation

Posted: Mon Oct 14, 2002 5:53 pm
by phpScott
I had a little trouble following your code but if I understand you right you call that calcution twice?
If that is that case then when you
if($rf1){$odds1 = $odds1 * (1 - $rf1);}
$total = ($odds1/$odds1a * $stake) + $stake;
if($deadheat1){$total = $total / $deadheat1;}

the first time you use this calcution you are assigning a new value to $odds1 which will have an effect the second time you call the calcution unless you redefine the value of $odds1 to its orginal value.

Just a thought

phpScott

Posted: Tue Oct 15, 2002 3:10 am
by martincrumlish
This is how the calcul;ation works (or is supposed to work)

The user fills in the form which contains the odds, deadheat, rule 4 and stake. The normal calculation is just $odds 1 / $odds1a * $stake + $stake.
ie: 2/1 bet with $1 on - 2 / 1 = 2 * 1 + 1 = 3

We can ignore deadheat, I have that working fine. If a user enters something for $rf1 then this triggers the if($rf1)
For example, the rule 4 is set to .20...this would be subtracted from 1.00 to get .80 $odds1 is then multiplied by .80 and this should get 1.6

That calculation is only called once if the value for $rf1 is passed. Once the page is submitted, I dotn see how it is being called twice. I noticed as well that .80 * 1.6 is 1.28 so it must be happening somehwere, I just cant see where or why

bothering me

Posted: Tue Oct 15, 2002 3:18 pm
by phpScott
I really want to help you out with this because now it is bothering me. Fro your calculation what are you returning is it $total or $stake. If you send me the zip file to phpScott@hotmail.com I will have a closer look because I seem to me missing something in the code that you have displayed.

Always trying to feel useful

phpScott