PHP - CASE CON IF ANIDADO NO RECONOCE LOS VALORES DEL IF CUANDO AGREGO OTROS

 
Vista:
sin imagen de perfil

CASE CON IF ANIDADO NO RECONOCE LOS VALORES DEL IF CUANDO AGREGO OTROS

Publicado por MANIGOLDO (1 intervención) el 21/01/2018 06:25:08
HOLA amigos mi problema es que cuando le doy mas opciones al IF este no reconoce los nuevos valores, por favor ayudenme

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
 
class Simulador
{
    private $monto = 0;
    private $plazo = 0;
    private $trea  = 0;
 
    public function __construct($monto, $plazo)
    {
        $this->monto = $monto;
        $this->plazo = $plazo;
        $this->calcularTrea();
    }
 
    /**
     * Permite retornar la trea de acuerdo al plazo y monto
     *
     * @return integer
     */
    private function calcularTrea()
    {
        switch ($this->monto) {
            case (($this->monto >= 500) && ($this->monto <= 10000)):
                if ($this->plazo >= 90 && $this->plazo <= 180) {
                    $this->trea = 5.0;
                } else if ($this->plazo >= 181 && $this->plazo <= 360) {
                    $this->trea = 8.0;
                } else if ($this->plazo >= 361 && $this->plazo <= 540) {
                    $this->trea = 10.0;
                } else if ($this->plazo >= 541) {
                    $this->trea = 11.0;
                } else {
                    $this->trea = 0;
                }
                break;
            case (($this->monto >= 10001) && ($this->monto <= 20000)):
                if ($this->plazo >= 90 && $this->plazo <= 180) {
                    $this->trea = 6.0;
                } else if ($this->plazo >= 181 && $this->plazo <= 360) {
                    $this->trea = 9.0;
                } else if ($this->plazo >= 361 && $this->plazo <= 540) {
                    $this->trea = 10.5;
                } else if ($this->plazo >= 541) {
                    $this->trea = 11.5;
                } else {
                    $this->trea = 0;
                }
                break;
            case (($this->monto >= 20001) && ($this->monto <= 30000)):
                if ($this->plazo >= 90 && $this->plazo <= 180) {
                    $this->trea = 7.0;
                } else if ($this->plazo >= 181 && $this->plazo <= 360) {
                    $this->trea = 10.0;
                } else if ($this->plazo >= 361 && $this->plazo <= 540) {
                    $this->trea = 11.0;
                } else if ($this->plazo >= 541) {
                    $this->trea = 12.0;
                } else {
                    $this->trea = 0;
                }
                break;
            case ($this->monto >= 30001):
                if ($this->plazo >= 90 && $this->plazo <= 180) {
                    $this->trea = 8.0;
                } else if ($this->plazo >= 181 && $this->plazo <= 360) {
                    $this->trea = 11.0;
                } else if ($this->plazo >= 361 && $this->plazo <= 540) {
                    $this->trea = 12.5;
                } else if ($this->plazo >= 541) {
                    $this->trea = 13.0;
                } else {
                    $this->trea = 0;
                }
                break;
            default:
                $this->trea = 0;
                break;
        }
    }
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de xve
Val: 3.943
Oro
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

CASE CON IF ANIDADO NO RECONOCE LOS VALORES DEL IF CUANDO AGREGO OTROS

Publicado por xve (6935 intervenciones) el 21/01/2018 19:49:26
En este código hay muchos if... exactamente cual es el que no funciona o no te hace caso?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de Alejandro
Val: 1.634
Plata
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

CASE CON IF ANIDADO NO RECONOCE LOS VALORES DEL IF CUANDO AGREGO OTROS

Publicado por Alejandro (839 intervenciones) el 24/01/2018 22:08:52
  • Alejandro se encuentra ahora conectado en el
  • chat de PHP
Los case estan mal, por ejemplo esta linea

1
case (($this->monto >= 500) && ($this->monto <= 10000)):

suponiendo que monto fuera 1500 en realidad tu linea lo que dice es

1
case (true):

Asi dependiendo las operaciones que se realizan al final lo que tienes es

1
2
3
4
5
6
7
8
9
10
switch($variable){
	case true:
		....
	case false:
		...
	case true:
		...
	case true:
		...
}
asi pues se realiza el caso en que $variable es true

intentalo asi
1
case >= 500 , <= 10000:
o asi
1
2
3
4
case >=500:
case <=1000:
	...
	break;

Espero que si me halla dado a entender.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar