Freight train and outrigger

-1

Good afternoon,

I am doing a function that returns the value of the postage to pay, where it is provided through intervals, that is:

Weight

asked by anonymous 05.07.2018 / 16:56

2 answers

0

Do a while while reducing weight:

$peso = 31;
$valor = 0;
while($peso >= 0){   
  if( $peso - 30 >= 0 ){
    $peso -= 30;
    $valor += 20;
  }
  if( $peso - 3 >= 0 ){
    $peso -= 3;
    $valor += 6;
  }
  if( $peso - 2 >= 0 ){
    $peso -= 2;
    $valor += 4;
  }
  if( $peso - 1 >= 0 ){
    $peso -= 1; 
    $valor += 3;
  }
}
    
05.07.2018 / 17:16
0

Make sure you do what you need.

$peso = 61;
$valor = 0;

while($peso != 0)
{  
 if( $peso >= 30)
{
    $peso -= 30;
    $valor += 20;
}
else if( $peso >= 3){
    $peso -= 1; 
    $valor += 6;
}
else if( $peso >= 2){
    $peso -= 1; 
    $valor += 4;
}
else if( $peso >= 1){
    $peso -= 1; 
    $valor += 3;
}

}

I hope I have helped.

    
05.07.2018 / 18:56