include<stdio.h>
#define PAY_RATE_1 8.75f
#define PAY_RATE_2 9.33f
#define PAY_RATE_3 10.00f
#define PAY_RATE_4 11.20f
#define TAX_RATE_FIRST_300 0.15f
#define TAX_RATE_NEXT_150 0.20f
#define TAX_RATE_REST 0.25f
#define OVERTIME_RATE 1.5f
int main()
{
int choice;
int hoursWorked;
float payRate;
float grossPay;
float taxes;
float netPay;
float overtimePay = 0;
printf("******************************************************************\n\n");
printf("Enter the number corresponding to the desired pay rate or action:\n\n");
printf("1) $8.75/hr\t\t\t\t2) $9.33/hr\n\n");
printf("3) $10.00/hr\t\t\t\t4) $11.20/hr\n\n");
printf("5) quit\n\n");
printf("******************************************************************\n\n");
scanf("%d", &choice);
// if entered choice is invalid, recycle
while(choice < 1 || choice > 5)
{
printf("\nWrong choice! Please select correct option\n\n");
printf("******************************************************************\n\n");
printf("Enter the number corresponding to the desired pay rate or action:\n\n");
printf("1) $8.75/hr\t\t\t\t2) $9.33/hr\n\n");
printf("3) $10.00/hr\t\t\t\t4) $11.20/hr\n\n");
printf("5) quit\n\n");
printf("******************************************************************\n\n");
scanf("%d", &choice);
}
// ask for hours worked
printf("\nPlease enter the number of hours worked: ");
scanf("%d", &hoursWorked);
// set pay rate as per the choice
switch(choice)
{
case 1:
payRate = PAY_RATE_1;
break;
case 2:
payRate = PAY_RATE_2;
break;
case 3:
payRate = PAY_RATE_3;
break;
case 4:
payRate = PAY_RATE_4;
break;
case 5:
return 0;
}
// check if overtime and gross pay
if(hoursWorked > 40)
{
overtimePay = (hoursWorked - 40) * payRate * OVERTIME_RATE;
grossPay = (40 * payRate) + overtimePay;
}
else
{
grossPay = hoursWorked * payRate;
}
// calculate taxes
if(grossPay <= 300)
taxes = grossPay * TAX_RATE_FIRST_300;
else if(grossPay <= 450)
taxes = grossPay * TAX_RATE_NEXT_150;
else
taxes = grossPay * TAX_RATE_REST;
// calculate net pay
netPay = grossPay - taxes;
// display gross pay, taxes and net pay
printf("\n\nGross Pay: $%.2f", grossPay);
printf("\nTaxes: $%.2f", taxes);
printf("\nNet Pay: $%.2f", netPay);
return 0;
}
Get Free Quote!
329 Experts Online