Calculate weekly net pay My task is:


  Write a program that requests the hours worked in a week and then
  prints the gross pay, the taxes, and the net pay. Assume the
  following:
  
  
  Basic pay rate = $10.00/hr
  Overtime (in excess of 40 hours) = time and a half
  Tax rate: 15% of the first $300
  
  20% of the next $150
  25% of the rest
  
  


Is my code way too long and complicated for that?

#include &lt;stdio.h&gt;
#define PAYRATE 10 //basic pay rate per hour
#define OVERTIME 15 //in excess of 40 hours a week
int NetPay(int hours);

int main()

{
    int userWeeklyHours;

    printf("Please enter your total weekly working hours: \n");
    scanf("%d", &amp;userWeeklyHours);// get the user weekly hours
    NetPay(userWeeklyHours);

    return 0;
}

int NetPay(int hours)// implementing the function to calculate total pay, total taxes, and net pay

{
    int firstRate, secondRate, restOfRate, secondAmount, rest, payAfterTax, payedBeforeTax, overHours;

    if (hours &gt; 40)
    {
        overHours = hours - 40;
        payedBeforeTax = (40 * PAYRATE) + (overHours * OVERTIME);
    }

    else
        payedBeforeTax = hours * PAYRATE;//defining the user first paycheck before taxes 

    if (payedBeforeTax &lt;= 300)//paying only first rate case
    {
        firstRate = payedBeforeTax*0.15;
        payAfterTax =payedBeforeTax - firstRate;
        printf("your total gross is %d, your taxes to pay are %d, your net pay is %d", payedBeforeTax, firstRate, payAfterTax);
    }

    else if (payedBeforeTax &gt; 300 &amp;&amp; payedBeforeTax &lt;= 450)//paying first and second rate
    {
        secondAmount = payedBeforeTax - 300;
        firstRate = (payedBeforeTax - secondAmount) * 0.15;
        secondRate = secondAmount * 0.20;
        payAfterTax = payedBeforeTax - (firstRate + secondRate);
        printf("your total gross is %d, your taxes to pay are %d, your net pay is %d", payedBeforeTax, firstRate + secondRate, payAfterTax);

    }

    else if (payedBeforeTax &gt; 450)// paying all rates 
    {
        rest = payedBeforeTax - 450;
        secondAmount = (payedBeforeTax - 300) - rest;
        firstRate = (payedBeforeTax - (rest + secondAmount)) * 0.15;
        secondRate = secondAmount * 0.20;
        restOfRate = rest * 0.25;
        payAfterTax = payedBeforeTax - (firstRate + secondRate + restOfRate);
        printf("your total gross is %d, your taxes to pay are %d, your net pay is %d", payedBeforeTax, firstRate + secondRate + restOfRate, payAfterTax);

    }

    return payAfterTax;
}
I'd start extracting some more functions.

What about decomposing

int NetPay(int hours){
    int payedBeforeTaxes = payedBeforeTaxes(hours);
    return applyTaxes(payedBeforeTaxes);
}

int payedBeforeTaxes(hours){
    return regularPay(hours) + overtimePay(hours);
}

int applyTaxes(int amountBeforeTaxes){
    int firstRateTaxes  = applyFirstRate(amountBeforeTaxes);
    int secondRateTaxes = applySecondRate(amountBeforeTaxes);
    int thirdRateTaxes  = applyThirdRate(amountBeforeTaxes);
    return amountBeforeTaxes - firstRateTaxes -
           secondRateTaxes - thirdRateTaxes;
}


At this point you just need to implement the functions with the appropriate code.
You'll notice that with this structure each function only does one thing and it will be much simpler and clearer.

Alternatively you can replace your apply taxes introducing an array of `(rate, threshold).
You will have to loop through the array, and at each step compute the amount you have to apply that tax rate and the associated tax amount.