Catch-22 claculating in PHP

Discussion in 'PHP' started by JasonGreen, Sep 13, 2009.

  1. #1
    There doesn't seem to be a way around this. I want to be able to calculate values using variables but in such a way that the value continues to change - however, I cannot simply write out the number, I need a variable.

    Here is the problem, look at my example below, if I were to use calculations based on define variable, I would end up using longer and longer calculations and that would be a horible mess.

    Like this

    print $serveryear . " " . $servercost . " " . ($servercost * HIGH_DEPREC) . " " . ($servercost - $servercost * HIGH_DEPREC) . "\n";
    print ($serveryear + 1) . " " . ($servercost - $dodgecost * HIGH_DEPREC) . " " . ($servercost - $servercost * HIGH_DEPREC * HIGH_DEPREC) . " " . ETC . "\n";
    It just grows and grows!!!!

    At the same time I cannot define a variable for each and every calculation, that too is a mess that grows and grows.

    DELL SERVER– Depreciation over 5-year period (Factor: .20)

    YEAR Start Value Deprec Ending Value

    2004 21297.00 4259.40 17037.60

    2005 17037.60 3407.52 13630.08
    2006
    2007
    2008

    Any insights, comments, and suggestions will be greatly appreaciated.

    Thanks
     
    JasonGreen, Sep 13, 2009 IP
  2. matthewrobertbell

    matthewrobertbell Peon

    Messages:
    781
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    0
    #2
    value = original value * (1-factor) ^ years ?

    eg 0.80 squared (2 years depreciation) is 0.64, so it would end up only being worth 64% of its original value.

    You may want to look into while and for loops as well :)
     
    matthewrobertbell, Sep 13, 2009 IP
  3. Fizzadar

    Fizzadar Well-Known Member

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    111
    #3
    Use a for loop along with powers to do the depreciation over and over.
     
    Fizzadar, Sep 13, 2009 IP