mardi 4 mai 2021

is there a reason my if statment isn't working?

I wrote this java code to calculate swedish taxes from the active tax tables 2018 (as a school assignment).

Although my code doesn't cooperate and won't react on my if statment but goes directly to my else if /else statements (skips the "if" even if the input is over 677300).

      var scan = new Scanner (System.in);
    double fskatt = 0.2;
    double mskatt =0.05;
    int free = 0;
    double g = 15000;
    double h = 662300;
    double l = 455300;  
    String svar;
    do{
        System.out.print("skriv in din brutto årsinkomst i svenska kronor:" + " ");
        double inkomst = scan.nextDouble();

        double lo = (inkomst - g - l) * fskatt;                        
        double hi = (inkomst - g - l) * fskatt +(inkomst - g - h)* mskatt;

        if (inkomst >= h + g)                                                  
            System.out.print ("Du kommer att betala:" + hi + "KR" + "  " + "i statligskatt/värnskatt" + "  ");

        else if (inkomst >= l + g)
            System.out.print ("Du kommer att betala:" + lo + "KR" + "  " + "i statligskatt/värnskatt" + "  ");

        else
            System.out.print ("Du kommer att betala:" + inkomst * free + "KR" + "  " + "i statligskatt/värnskatt" + "  ");
        System.out.println("Vill du göra en till beräkning? Ja eller Nej");
        svar = scan.next();
    }
    while (svar.equalsIgnoreCase("ja"));
}

}

Aucun commentaire:

Enregistrer un commentaire