hi everyone
i havent been here in a long while since i have been here anyway, i am doing a program(practicing) but i dont or cant say if it is my calculation is off
everything is working properly except for the the income tax part. it is outputting zero. tell me what is wrong with my calculation and how do i go about fixing it. thanks much in advance.

 final double health_surcharge = 33.50;

        double hrs, hrswrk, gsalary = 0, NIS,nsalary=0, rate_of_pay = 0,totaldeduct = 0, incometax, teaching_allow;
        double overtime = 0, income_tax = 0, total_tax;


        System.out.println("please enter the lecturer id number");
        String lecturerID = userinput.nextLine();

        System.out.println("please enter the lecturer first name");
        String firstname = userinput.next();

        System.out.println("please enter the lecturer last name");
        String lastname = userinput.next();

        System.out.println("please enter the number of hours work");
        hrswrk = userinput.nextDouble();

        System.out.println("please enter the teaching allowance");
        teaching_allow = userinput.nextDouble();

        System.out.println("please enter your NIS contribution");
        NIS = userinput.nextDouble();


        hrs = (hrswrk * rate_of_pay) + teaching_allow;
        hrs = (overtime * rate_of_pay);
        total_tax = (health_surcharge + NIS) + (gsalary * 0.5);
        total_tax = (gsalary * 0.5);
        gsalary = (gsalary + teaching_allow);
        totaldeduct =(NIS + health_surcharge);
        nsalary = (gsalary - totaldeduct);


        System.out.println("the lecturer id is "+ lecturerID);
        System.out.println("the lecturer first and last name is "+ firstname +lastname);
        System.out.println("the hours worked is "+ hrswrk);
        System.out.println("the income tax is "+income_tax);
        System.out.println("the total deduction is "+totaldeduct);
        System.out.println("the gross salary is "+gsalary);
        System.out.println("the net salary is "+nsalary);

You never assign income_tax a value other than 0 when you declare it. You do, however, calculate total_tax twice. Should one of those possibly be income_tax instead?

i am totally lost at what value ah should put.

Typically your income_tax will be some percentage of another value. Figure out what that other value is and calculate a percentage of it.

I'm sorry, but lines 26-32 are complete nonsense. Just delete them and start again by doing the following:
1. Keep a copy of the requirements in front of you at all time - they should detail the calculations to be done.
2. Give your variables descriptive accurate names - eg you have a var hrs that looks like it holds a number of hours, but actually seems to hold monetary amounts. Name them so it's explicit whether a var is a number of hours, a percentage or a monetary amount. That will help avoid fundamental errors like adding together a percentage and a quantity.
3. Get a sheet of paper. write down all your vars with a space to write their values. Write down a typical test case.
4. Try to code the very first step of the calculation. Pretend you are the computer and use your sheet of paper to follow the instructions in that line of code.
5. If/when that seems to make sense, go on to the next line.
6. Repeat until the calculations are complete and your sheet of paper is showing a complete set of correct values.
7. Remember the take-away moral, which is that if you can't run through your calculations on a sheet of paper then you certainly have no idea how to code them as a program.

If that seems too tedious, you can always use the Alternative Approach:
1. Take a few random guesses as to what code might be correct
2. Watch it fail to compile or execute with incorrect results.
3. Throw hands up in despair

:) JC

commented: Hah! +14

I will try that james and thank you reverend jim

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.