help me with this java code?

-1

The problem asks me that given "n" number of products request a conversion of dollars to pesos, the dollar has a value of $ 19.10, and tells me that if the purchase is $ 300 no discount is applied, if the purchase goes from $ 300 to $ 1000 40% discount applies, and if the purchase is greater than $ 1000 60% discount applies

public static void main(String[] args) {
    Scanner leer=new Scanner (System.in);

    System.out.println("Introduzca la cantidad de dinero en dolares");
    int dolar=leer.nextInt();
    double a,b;
    a=19.10;
    b=dolar*a;
    double N = 0,monto =;

    if(N<=300){
        monto=N;
        System.out.println(monto);
    } 
    else if(N>=300 && N>=1000){
        monto= N-(N*0.4);
        System.out.println(monto);
    }
    else if(N>1000){
        monto= N-(N*0.6);
        System.out.println(monto);
    }
    else{
        System.out.println(N);
    }




}
    
asked by Felipe Reyes Salazar 14.02.2018 в 05:40
source

1 answer

1

As gbianchi has said in one of the comments, the variable N is initialized to 0 and no value is passed, therefore your logic with the if will never yield the result you expect.

The simplest option would be to replace the variable N with b and with that, the logic would already apply.

double a, N, monto; //Eliminamos la variable b y creamos la variable N en su lugar
a=19.10;
N=dolar*a;
if(N<=300){
.
.
//resto de la lógica
    
answered by 14.02.2018 в 09:19