Jump to content

Math Equation


Graxeon

Recommended Posts

I have a math equation that calculates profit. What I don't know how to implement is "times." Times is how many times you repeat the equation. Each time you repeat it though, it uses the new TOTAL cash.

 

So let's say I had this:

 

equation.php?cash=100&cost=20&profit=3&times=7

 

It should calculate this:

 

100/20 = 5

5*3 = 15

(now it calculates the "times")

100+15 = 115

115/20 = 5.75

5.75*3 = 17.25

("times" #3)

115+17.25 = 132.25

132.25/20 = 6.6125

6.6125*3 = 19.8375

(then keep repeating until you get to "&times=7")

 

<?php

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


$equation = $cash / $cost * $profit;
//I don't know how to implement $times

echo $equation;

?>

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

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

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

echo $equation;

Im assuming you want a complete total with this script :P

Link to comment
https://forums.phpfreaks.com/topic/188910-math-equation/#findComment-997420
Share on other sites

He was just giving you a run down of how to do a for loop.. Thats all.

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

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

echo $cash;

 

I think is correct now.. I didnt read your post properly.. :D (Its 3am)

Link to comment
https://forums.phpfreaks.com/topic/188910-math-equation/#findComment-997426
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.