Help with payrate calculation

Associate
Joined
11 Jun 2006
Posts
1,569
I need help on the structure i need to use to get the correct answers to display.
I have a simple hours worked * payrate calculation but it gets confusing when trying to bring in NI and tax etc

My scenario short ver:
Paid an hourly wage
If hours are over 40 they are paid overtime 1.5x the amount normally
NI deducted gross pay 9% (0.09)
gross pay before tax
net pay after tax
income tax 25% of anything earned over £80 - first £80 is tax free

surely im wrong in trying
If hours worked =< 40
then perform payrate * hours as i have done
else if
hours worked + overtime? (im lost, hours-40 * 1.5 then + 40) Its not right but all input i have sry lol
NI 0.09-pay
store as netpay
if netpay => 80 then
netpay - 0.25%
else output pay

Its not that complicated atall but im making a mess as you can see, and want to get this working, all help apprecaited!

global variables
Code:
  int hoursWorked = 0; //Declaring variable as interger
        double payRate = 0.0; //Declaring variable as Decimal
        double pay = 0.0; //Declares variable as decimal

Code:
  private void payCalc(int hoursWorked, double payRate)
        {
           
            
            pay = hoursWorked * payRate; //calculation used for form
            MessageBox.Show("Your pay is: " + pay); //display messagebox
            
           
        }


        private void btnSubmit_Click(object sender, EventArgs e)
        {
           
            hoursWorked = int.Parse(txtHours.Text); //This converts it from textbox into integer and puts it in hoursworked
            payRate = double.Parse(txtPayrate.Text); //This converts text from txtpay into integer and into payrate variable

            payCalc(hoursWorked, payRate);
            }
 
I have something thats looking better but still isnt working
Code:
  {

                //  Calculate the initial pay

                pay = hoursWorked * payRate;

                //  Add on overtime pay (half of the remaining hours above forty)

                double overTime = (hoursWorked - 40);

                if (overTime < 0) { overTime = 0; }

                pay += ((overTime * payRate) / 2);

                //  Take off 9% NI

                pay = (pay * 0.91);

                //  If we have more than 80 pounds, work out how much should be taken off

                double amount_to_tax = 0;

                if (pay > 80) { amount_to_tax = ((pay - 80) / 4); }

                //  Calculate the net pay, take off any tax

                double net_pay = (pay - amount_to_tax);

                //  Print out our results

                MessageBox.Show("Gross Pay: " + pay + "\n Net Pay: " + net_pay); //display messagebox

            }
 
Back
Top Bottom