mardi 25 octobre 2016

"Illegal start of expression" error with else if

I'm trying to do an else if statement within a switch, but I keep getting "illegal start of expression error." The error usually pops up at the <= within case 1. I tried adding parentheses and brackets to see if that was the issue, but it wasn't.

    import java.util.Scanner;

    public class InvoiceApp
    {
        public static void main(String[] args)
        {
            //Declare variables and Scanner object
            float subtotal;
            int customerType;
            double discountAmount;
            double discountPercent;
            double total;

            Scanner keyboard = new Scanner(System.in);

            //Prompt user for subtotal   
            System.out.println("Please enter the subtotal: ");

            //Read subtotal
            subtotal = keyboard.nextFloat();

            //Calculate Discount Rate
            switch(customerType) {
                case 1: if  (subtotal >= 500) discountPercent = 20;

                        else if (subtotal < 500 && <= 250) 
                            discountPercent = 15; 

                        else if (subtotal < 250 && <= 100) 
                            discountPercent = 10; 

                        else if (subtotal < 100) 
                            discountPercent = 0; 



            }               

Aucun commentaire:

Enregistrer un commentaire