Please assit with correcting the code below basesd on the text in Bold. Please r
ID: 3800938 • Letter: P
Question
Please assit with correcting the code below basesd on the text in Bold. Please read entire post. last attempt to get this right. Thanks
The pay calculator still does not calculate the taxes correctly. Remember that only the amount over $600.00 is taxed at 20% - the first $600.00 is taxed at 15%. If the gross is over 600, subtract 600 from the gross and multiply the difference by 0.20 and then add 600 * 0.15 to get the total taxes. It's better to multiply by decimal amounts rather than use integers and then divide. You will need to reconsider some of the data types for the variables. int isn't the best choice when dealing with monetary amounts. The hours could also contain a decimal. The indentation is not consistently correct but the code includes comments.
Instructions
Write a program that requests the user to enter hours worked in a week and the hourly wage. The program should then print the gross pay, the taxes, and the net pay. Assume the following:
Overtime (in excess of 40 hours for week) = time and a half.
Tax rate: 15% of the first $600, 20% of the rest.
Code
#include<stdio.h>
int main()
{
// integer declaration
int workhours,hourlywage,taxrate,othour,otwage;
//salary, tax, net pay are float variables
float salary,tax,netpay;
printf(" Please enter hours worked for the week ");
//user enter weekly hours
scanf("%d",&workhours);
// enter hourly wage
printf("Please enter your hourly wage ");
//user enter hourly rate
scanf("%d",&hourlywage);
// if hours worked is equal to 40
if(workhours<=40)
{
salary=workhours*hourlywage;
//if salary is less than or equal to 600
if(salary<=600)
{
//tax rate is equal to 15
taxrate=15;
tax=(taxrate*salary)/100;
//net pay equals salary minus tax
netpay=salary-tax;
printf("Total gross Pay Tax Rate Net Pay ");
//print gross pay minus tax rate and total netpay
printf("$ %f $ %f(15%%) $ %f ",salary,tax,netpay);
}
else
{
//tax rate equals 20%
taxrate=20;
tax=(taxrate*salary)/100;
//total net pay salary minus tax rate
netpay=salary-tax;
//print total gross pay, tax rate, and net pay
printf("Total gross Pay Tax Rate Net Pay ");
printf("$ %f $ %f(20%%) $ %f ",salary,tax,netpay);
}
}
else
{
othour=workhours-40;
otwage=hourlywage+(hourlywage/2);
salary=(40*hourlywage)+(othour*otwage);
if(salary<=600)
{
taxrate=15;
tax=(taxrate*salary)/100;
//net pay equals salary minus tax
netpay=salary-tax;
printf("Gross Pay Tax Rate Net Pay ");
printf("$ %f $ %f(15%%) $ %f ",salary,tax,netpay);
}
else
{
//tax rate equals 20 percent
taxrate=20;
tax=(taxrate*salary)/100;
//net pay equals salary minus tax
netpay=salary-tax;
printf("Gross Pay Tax Rate Net Pay ");
printf("$ %f $ %f(20%%) $ %f ",salary,tax,netpay);
}
}
return 0;
Explanation / Answer
Find comments inline for fixes. Also made few formatting changes by removing spaces in the output lines.
PROGRAM CODE:
#include<stdio.h>
int main()
{
// integer declaration
//changing all int to float
float workhours,hourlywage,taxrate,othour,otwage; //FIX: Changed the data type to float for all the variables.
//salary, tax, net pay are float variables
float salary,tax,netpay;
printf("Please enter hours worked for the week ");
//user enter weekly hours
scanf("%f",&workhours);
// enter hourly wage
printf("Please enter your hourly wage ");
//user enter hourly rate
scanf("%f",&hourlywage);
// if hours worked is equal to 40
if(workhours<=40)
{
salary=workhours*hourlywage;
//if salary is less than or equal to 600
if(salary<=600)
{
//tax rate is equal to 15
taxrate=0.15;
tax=taxrate*salary;
//net pay equals salary minus tax
netpay=salary-tax;
printf("Gross Pay Tax Rate Net Pay ");
//print gross pay minus tax rate and total netpay
printf("$ %f $ %f(15%%) $ %f ",salary,tax,netpay);
}
else
{
//tax rate equals 20%
taxrate=0.20;
tax=(0.15 * 600) + taxrate*(salary-600); //FIX: changed the tax calculation to take 15% for first $600 and 20% thereon
//total net pay salary minus tax rate
netpay=salary-tax;
//print total gross pay, tax rate, and net pay
printf("Gross Pay Tax Rate Net Pay ");
printf("$ %f $ %f(20%%) $ %f ",salary,tax,netpay);
}
}
else
{
othour=workhours-40;
otwage=hourlywage+(hourlywage/2);
salary=(40*hourlywage)+(othour*otwage);
if(salary<=600)
{
taxrate=0.15;
tax=taxrate*salary;
//net pay equals salary minus tax
netpay=salary-tax;
printf("Gross Pay Tax Rate Net Pay ");
printf("$ %f $ %f(15%%) $ %f ",salary,tax,netpay);
}
else
{
//tax rate equals 20 percent
taxrate=0.20;
tax=(0.15 * 600) + taxrate*(salary-600); //FIX: changed the tax calculation to take 15% for first $600 and 20% thereon
//net pay equals salary minus tax
netpay=salary-tax;
printf("Gross Pay Tax Rate Net Pay ");
printf("$ %f $ %f(20%%) $ %f ",salary,tax,netpay);
}
}
return 0;
}
OUTPUT: