jeudi 7 octobre 2021

Why the if method it's ignored or doesn't work?

I want to calculate how much money would someone save in the end of one year, each month that person does a bank deposit, but if the deposit is greater than the amount of money they have at that moment, they get a bonus of 1% of the deposit of the month, if it's not greater, then the bonus doesn't get added, the problem is that the bonus does not get added to the money saved, even when i specify to do that

    float ahorroActual;
    float depositosMensuales;
    int conteoMeses=1;
    int acumulador=1;
    float sumaAhorros=0;
    float ahorroMes;
    float ahorroBono;
    float ahorroConBono;
    
while (conteoMeses<13){
    System.out.println("Ingrese el deposito del mes "+((int)conteoMeses));
    depositosMensuales=leer.nextFloat();
    float totalAhorrado = sumaAhorros+=depositosMensuales;
    
    //This is where the bonus is supposed to get added, but for some reason, it doesn't
    if (depositosMensuales>totalAhorrado){
        ahorroConBono=0.01f*depositosMensuales;
        ahorroBono=totalAhorrado+ahorroConBono;
        System.out.println("Su ahorro en el mes " + conteoMeses + " con bono añadido es de "+ ahorroBono);
    } else{
            System.out.println("Su ahorro en el mes " + conteoMeses + " es de "+ totalAhorrado);
            }
            
        conteoMeses=conteoMeses+acumulador;
    }
}

}

Aucun commentaire:

Enregistrer un commentaire