please solve the math equation in php

Discussion in 'PHP' started by verak123, Jan 19, 2012.

  1. #1
    hi all i have a problem not solved by me the math equation in php. following is behavior what i want.

    i have 5 digits ( 1 , 2 , 3 , 4 , 5)

    if it is 1 then provide a equation that return a digit -15
    if it is 2 then provide a equation that return a digit -12
    if it is 3 then provide a equation that return a digit -9
    if it is 4 then provide a equation that return a digit -6
    if it is 5 then provide a equation that return a digit -3

    equation must same for all digits.
    explained again as:

    1 equation = -15
    2 equation = -12
    3 equation = -9
    4 equation = -6
    5 equation = -3

    what will be equation?
    i will be very thank full to try to solve my problem.
     
    verak123, Jan 19, 2012 IP
  2. Irfi0009

    Irfi0009 Banned

    Messages:
    17,584
    Likes Received:
    33
    Best Answers:
    1
    Trophy Points:
    48
    #2
    using a switch statement it can b solved.............
     
    Irfi0009, Jan 19, 2012 IP
  3. verak123

    verak123 Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thanks jinGKing but i want to solve it by just one equation. i am working on a site that will be handle by this equation. not by lengthy code.
     
    verak123, Jan 19, 2012 IP
  4. dujmovicv

    dujmovicv Member

    Messages:
    62
    Likes Received:
    2
    Best Answers:
    4
    Trophy Points:
    48
    #4
    I think this is more a math problem than a PHP problem :)
    Try to post in math forums. Come back when you have the equation and we'll do the php part...
     
    dujmovicv, Jan 20, 2012 IP
  5. verak123

    verak123 Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    thanks dujmovicv
     
    verak123, Jan 20, 2012 IP
  6. proactiv3

    proactiv3 Peon

    Messages:
    55
    Likes Received:
    7
    Best Answers:
    4
    Trophy Points:
    0
    #6
    Well, it seems a rather simple problem to me: y = 3x - 18

    If x = 1, y = -15
    If x = 2, y = -12
    If x = 3, y = -9
    If x = 4, y = -6
    If x = 5, y = -3

    Hence:

    $result = (3 * $input) - 18
    Code (markup):
     
    proactiv3, Jan 20, 2012 IP
    jestep likes this.