how can I make a calculator?

Discussion in 'PHP' started by shedokan, Feb 6, 2008.

  1. #1
    Hi,
    Can someone help me with creating this calculator or tell me how to do it best?

    I have 20 different fields and in each you put a different series of numbers in (each one has 6 digits in it) also I have one field called "number1" and one called "targetnumber"

    in the field called "numebr1" you put (type) a certain series of digits (6 numbers). in the middle you have 2 fields for modifier numbers. the Script has to place different series of digits in these fields from the list of (about) 20 different options in the 2 modifier fields - so that : Number 1 + modifier1 + modyfier 2 = (will eqal) "targetnumber" (which you also need to type in the begining) until it finds 2 numbers that fit. for example :

    Number1 : 1-2-3-4-5-6

    Modifier 1 :

    modifier 2 :

    TargetNumber : 4-5-6-7-8-9

    the script choses the correct 2 options to put between the target number to number 1 out of the 20 options you typed in the begining. and lets say 2 of your options were : 1-1-1-1-1-1 and 2-2-2-2-2-2 so the Script will put them in the modifier fields, like this :

    Modifier 1 : 1-1-1-1-1-1

    Modifier 2 : 2-2-2-2-2-2

    (which is the correct answer)

    the series of numbers are not 1 number, but 1 serie so every number is independent - for example :

    0-1-5-9-9-9

    +

    1-5-5-1-1-1

    will equale =

    1-6-10-10-10-10

    (also I must add - 0 is an independent and important number , and should not be ignored even if it's placed in the begining of the number) .

    so the first digit in the serie of "number1" is added with the first digit from the series of numbers from "modifier1 " and then it gets added with the first Number of the series of numbers from "modifier2". then if it gets matched with the first digit of the TargetNumber it begins trying to match the second digit, then third...etc. if one of the resulted digits doesen't match with the TargetNumber's digit (in the same spot) it changes that series of numbers and places a different serie of digits from the given list instead , until it finds the correct 2 options that work (it has to go through all of the possible combos) .

    that's basicly what I am trying to do.

    thanks.
     
    shedokan, Feb 6, 2008 IP
  2. dbl07dee

    dbl07dee Member

    Messages:
    43
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #2
    It sounds like you need to be manipulating arrays

    array1: a1,a2,a3,a4,a5 : A
    array2: b1,b2,b3,b4,b5 :B

    operations results array3: C
    c1=b1+a1 or c1=a1-b1....

    Declare arrays in dimension statement
     
    dbl07dee, Feb 6, 2008 IP
  3. shedokan

    shedokan Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    this is what I have so far but I can't see why it doesn't works:
    $key=(isset($_POST['key']))?$_POST['key']:'000000';
    $mod1='000000';
    $mod2='000000';
    $res='000000';
    $tar=(isset($_POST['tar']))?$_POST['tar']:'000000';
    if(isset($_POST['confirm'])){
    $options=$_POST['option'];
    $keyr = str_split($key);
    $tarr=str_split($tar);
    for($i=1;$i<=count($options);$i++){
    $options[$i] = str_split($options[$i]);
    }
    for($a=0;$a<=5;$a++){
    for($b=0;$b<=18;$b++){
    for($c=0;$c<=5;$c++){
    for($d=0;$d<=5;$d++){
    $int=$keyr[$a]+$options[1][$c]+$options[$b][$d];
    echo $i." : ".$keyr[$a]+$options[1][$c]+$options[$b][$d]."<br>";
    if($int==$tarr[$])
    echo "good$i<br>";
    }
    }
    }
    }
    echo $good1;
    }
    
    PHP:
     
    shedokan, Feb 6, 2008 IP
  4. ts1993

    ts1993 Active Member

    Messages:
    112
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    53
    #4
    Hi all im working on a copy of bux.to (ptc site) somebody interseting send my a private message
     
    ts1993, Feb 7, 2008 IP