Jump to content

Equation Problem


Graxeon

Recommended Posts

I'm trying to echo how many times it takes to get rid of an item (the equation is in the if statement):

 

<?php

$cash = $_GET['cash'];
$cost = $_GET['cost'];
$profit = $_GET['profit'];
$times = $_GET['times'];

$equation = 0;
for ($i=0;$i<$times;$i++) {
$cash+= ($cash / $cost * $profit);
}



$originalcash = $_GET['cash'];
$profitnew = $cash - $originalcash;
$buystarting = $originalcash / $cost;
$buyending = $cash / $cost;

echo "Starting Cash: " . number_format($originalcash,2,'.',',');
echo "<br />Ending Cash: " . number_format($cash,2,'.',',');
echo "<br />Total Profit: <b>" . number_format($profitnew,2,'.',',') . "</b>";
echo "<br />";
echo "<br />Cost per item: " . number_format($cost,2,'.',',');
echo "<br />Profit per item: " . number_format($profit,2,'.',',');
echo "<br />Times: " . number_format($times,2,'.',',');
echo "<br />Total items you can buy with Starting Cash: " . number_format($buystarting,2,'.',',');
echo "<br />Total items you can buy with Ending Cash: " . number_format($buyending,2,'.',',');

echo "<br /><br />";

$unlock = $_GET['unlock'];
if($unlock=="yes") {
     $shards = $_GET['shards'];
     $shardsstarting = $shards * $buystarting;
     $shardsending = $shards * $buyending;
     $trades = $shardsstarting / 50000;
     $trades2 = $shardsending / 50000;

     echo "<br />Total Shards made with Starting Cash: " . number_format($shardsstarting,2,'.',',');
     echo "<br />Total trades at start: " . number_format($trades,2,'.',',');
     echo "<br />Total Shards made with Ending Cash: " . number_format($shardsending,2,'.',',');
     echo "<br />Total trades at end: " . number_format($trades2,2,'.',',');

     $originalcash2 = $_GET['cash'];
     $equation2 = 0;
     for ($i=0;$i<$times;$i++) {
     $originalcash2+= ($originalcash2 / $cost * $shards / 50000);
     }
     echo "<br />Total Trades: " . number_format($originalcash2,2,'.',',');
        exit;
   }


?>

 

It's outputting the correct amount of times it takes to get rid of the "shards" but it's also adding "$originalcash" to it. If I try subtracting "$originalcash" then it gives me a totally different number (not what you'd expect).

 

How can I fix it to just show how many times it takes to get rid of "$equation2"?

 

So say the we had this:

 

equation.php?cash=100&cost=20&profit=4&times=7&shards=59&unlock=yes

 

To find out how many times it takes to get rid of $equation2 this would happen:

 

100/20 = 5

5*59 = 295 (first set of shards out of "&times=3")

(start 2nd "&times=3")

120/20 = 6 (120 is $cash + $cash/$cost * $profit)

6*59 = 354 (second set of shards out 3)

(start 3rd "&times=3")

144/20 = 7.2

7.2*59 = 424.8

(now add up all of the values)

295+354+424.8 = 1073.8

(now divive by 50,000)

1073.8/50000 = 0.021476 (50,000 is just a number I picked)

Link to comment
https://forums.phpfreaks.com/topic/188926-equation-problem/
Share on other sites

Let me shorten the post a little :P

 

Here's my equation:

 

     $originalcash2 = $_GET['cash'];
     $equation2 = 0;
     for ($i=0;$i<$times;$i++) {
     $originalcash2+= ($originalcash2 / $cost * $shards / 50000);
     }
     echo "<br />Total Trades: " . number_format($originalcash2,2,'.',',');
        exit;
   }

 

I call that script by saying:

 

equation.php?cash=100&cost=20&profit=4&times=7&shards=59&unlock=yes

 

And I need the equation to do this:

 

100/20 = 5

5*59 = 295 (first set of shards out of "&times=3")

(start 2nd "&times=3")

120/20 = 6 (120 is $cash + $cash/$cost * $profit)

6*59 = 354 (second set of shards out 3)

(start 3rd "&times=3")

144/20 = 7.2

7.2*59 = 424.8

(now add up all of the values)

295+354+424.8 = 1073.8

(now divive by 50,000)

1073.8/50000 = 0.021476 (50,000 is just a number I picked)

Link to comment
https://forums.phpfreaks.com/topic/188926-equation-problem/#findComment-997683
Share on other sites

Any ideas? :P

Can you implement your calculation in a loop? You could fairly easily iterate a count for each time the number is modified, store it into an array and count it (or simply +1 to a number).

 

     $originalcash2 = $_GET['cash'];
     $equation2 = 0;
     $c = 0;
     for ($i=0;$i<$times;$i++) {
     $originalcash2+= ($originalcash2 / $cost * $shards / 50000);
     $c++;
     }
     echo "<br />Total Trades: " . number_format($originalcash2,2,'.',',');
        exit;
   }

Link to comment
https://forums.phpfreaks.com/topic/188926-equation-problem/#findComment-997819
Share on other sites

uh, i may be missing the point entirely but..

 

You mean this?

 

Change "+=" to "=" on line 48

 

-CB-

 

That works but only if "times=1". If it's anything higher than 1 then it just displays 0.

 

Same test page:

 

http://t3st1ng.ulmb.com/equation.php?cash=14000000&cost=1532&profit=18&times=2&shards=59&unlock=yes

Link to comment
https://forums.phpfreaks.com/topic/188926-equation-problem/#findComment-998167
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.