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 <stdio.h>
#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", &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 > 40)
{
overHours = hours - 40;
payedBeforeTax = (40 * PAYRATE) + (overHours * OVERTIME);
}
else
payedBeforeTax = hours * PAYRATE;//defining the user first paycheck before taxes
if (payedBeforeTax <= 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 > 300 && payedBeforeTax <= 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 > 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;
}