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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.