I have a game where the user picks 6 random numbers in different order, and then finally the sum of their differences are added to give a score. As an example, the user would pick the following 6 numbers in the following order (lowest to highest):
10, 12, 12, 14, 14, 14
What the script should do is subract 14 from 14, get 0 and then keep moving down the line adding the difference. The final score that should be reported for this number set is 4.
However, although I thought this was simple, I set up a quick loop to add the differences and got a score of -10:
for($i=6; $i>1; $i--){
$score = $_GET["v".($i)] - $_GET["v".($i-1)];
echo $score . ' > ';
}
The variables are named v6 through v1 based on their position. I echoed the values and got a print out as follows:
-14 > 0 > 2 > 0 > 2 >
Any ideas why that first value is -14??
Its driving me insane!
Thanks!
10, 12, 12, 14, 14, 14
What the script should do is subract 14 from 14, get 0 and then keep moving down the line adding the difference. The final score that should be reported for this number set is 4.
However, although I thought this was simple, I set up a quick loop to add the differences and got a score of -10:
for($i=6; $i>1; $i--){
$score = $_GET["v".($i)] - $_GET["v".($i-1)];
echo $score . ' > ';
}
The variables are named v6 through v1 based on their position. I echoed the values and got a print out as follows:
-14 > 0 > 2 > 0 > 2 >
Any ideas why that first value is -14??
Its driving me insane!
Thanks!