char F, f, H, h, C, c;
            double hours_worked, grosspay, netpay, rateof_pay, total_deduction, deduction, overtime, extra_time;
            double comm_incent, fixedsalary = 0, taxfree_allow, totalgross_pay, totalnetpay, totalsales = 0;
            String empfirst_name, emplast_name, hourlypaid_workers, payroll_report, payroll_payslip, process_workers, monthlyfixed_workers;
            String commiss_workers;
            int taxes, emp_idnum, highest, lowest,highestpaid_workers, lowestpaid_workers, highestvalue_workers, lowestvalue_workers;
            char inputChar = 0, Char;



            for(int i=1; i<=3; i++){

                System.out.println("please enter the employee id number");
                emp_idnum = input.nextInt();

                System.out.println("please enter the employee first name");
                empfirst_name = input.next();

                System.out.println("please enter the employee last name");
                emplast_name = input.next();



               inputChar = input.next().charAt(0);
             if(Character.toUpperCase(inputChar) ==('F') || Character.toLowerCase(inputChar) ==('f')){



               System.out.println("/enter your usercode");
               System.out.println("please enter the employee fixed salary");
               fixedsalary = input.nextDouble();


             inputChar = input.next().charAt(0);
            else if(Character.toUpperCase(inputChar) == ('C') || Character.toLowerCase(inputChar) == ('c')){


               System.out.println("enter your usercode");
               System.out.println("please enter the employee fixed salary " + fixedsalary);
               fixedsalary = input.nextDouble();
               System.out.println("please enter the total sales of the month " + totalsales);
               totalsales = input.nextDouble();



             inputChar = input.next().charAt(0);
             else if(Character.toUpperCase(inputChar)== ('H') || Character.toLowerCase(inputChar)== ('h'));
        }


         }    

     }
 am now getting an error here. the error is an else without an if

does inputchar have any value, do I need to change it. have been working on this payroll system for a company, it say the user will either enter c or C for commission worker, f or F for a fixed monthly worker or h or H for a hourly paid worker. I have been trying to say that when a worker enter either c or capital C they are a commission worker likewise for the other two and the program would accept either letter may be common or capital and i am stuck at the moment . the error am receiving is else without an if

can someone explain to me how to get past this what does it mean and how to fix it

Recommended Answers

All 7 Replies

Hi

You are missing some braces which is why the compiler sees an else without an if statement.

The syntax should should be:

    if (your test)
    {
        //do some stuff
    }
    else if (another test)
    {
        //do some other stuff
    }

HTH

hi hi dijeavon

just add in the braces and still having the same errors

Hi

Can you post your code as it is now please.

here it is again and still getting the same error

Scanner input = new Scanner (System.in);

            char F, f, H, h, C, c;
            double hrswrked, grosspay, netpay, payrate, total_deduction, deduction, overtime, extra_time;
            double comm_incent, fixedsalary = 0, taxfree_allow, totalgross_pay, totalnetpay, totalsales = 0;
            String empfirst_name, emplast_name, hourlypaid_workers, payroll_report, payroll_payslip, process_workers, monthlyfixed_workers;
            String commiss_workers;
            int taxes, emp_idnum, highest, lowest,highestpaid_workers, lowestpaid_workers, highestvalue_workers, lowestvalue_workers;
            char inputChar = 0, Char;



            for(int i=1; i<=3; i++){

                System.out.println("please enter the employee id number");
                emp_idnum = input.nextInt();

                System.out.println("please enter the employee first name");
                empfirst_name = input.next();

                System.out.println("please enter the employee last name");
                emplast_name = input.next();



             inputChar = input.next().charAt(0);
             if(Character.toUpperCase(inputChar) ==('F') || Character.toLowerCase(inputChar) ==('f')){



               System.out.println("/enter your usercode");
               System.out.println("please enter the employee fixed salary");
               fixedsalary = input.nextDouble();
             } 

              inputChar = input.next().charAt(0);
               else if(Character.toUpperCase(inputChar) == ('C') || Character.toLowerCase(inputChar) == ('c'))
            {  

               System.out.println("enter your usercode");
               System.out.println("please enter the employee fixed salary " + fixedsalary);
               fixedsalary = input.nextDouble();
               System.out.println("please enter the total sales of the month " + totalsales);
               totalsales = input.nextDouble();

            }

               inputChar = input.next().charAt(0);
               else if(Character.toUpperCase(inputChar)== ('H') || Character.toLowerCase(inputChar)== ('h'))
            {
                 System.out.println("please enter the pay rate");
                 payrate = input.nextDouble();

                 System.out.println("please enter the hours of work for the month");
                 hrswrked = input.nextDouble();
            }


         }    

     }

Hi

You have the code line inputChar = input.next().charAt(0); above each else if statement which is breaking the flow. I would hazard a guess that this is a result of copying and pasting from your original if statement. This is what is causing the error.

HTH

before I can comment on your code I need to get your logic behind it. You get user's details and then the user enters a char that you want to find out whether it is 'f'/'c' or 'h', correct? If so, you shouldn't ask for a new char after each if/else if statement but just proceed with the one you got before the if/else statement. Further
if(Character.toUpperCase(inputChar) ==('F') || Character.toLowerCase(inputChar) ==('f')) - do you understand what is the meaning of this? it is basically the same operation thus it is not relevant as the first part of the statement is enough to achieve your idea behind 'no matter what character is entered, get it to uppercase and compare to 'F'' if this fails to evaluate to true, the second will fail too as you are simply doing the same thing comparing to the same character

So all in all, remove line 36 and 48

thank you both guys, slavi and dijeavons very much

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.