Jump to content

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

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.