Still looking for help with problem. Here what i have so far. having trouble get
ID: 668594 • Letter: S
Question
Still looking for help with problem. Here what i have so far. having trouble getting it to add everything like it should and cancelling when i put in -1
#include<stdio.h>
#include<math.h>
int main(void)
{
int dependents, netpay, taxes, employees, hoursworked;
double grosspay=0, rate=0, salary=0;
while (hoursworked>=0)
{
printf("Enter # of hours worked( -1 to end): ");
scanf("%d",&hoursworked);
printf("Enter hourly rate of pay: ");
scanf("%f",&rate);
printf("Enter number of dependents: ");
scanf("%d",&dependents);
employees++;
if(hoursworked<=40)
{
salary=(hoursworked*rate);
}
else
{
salary=(40*rate)+((hoursworked-40)*(1.5*rate));
}
grosspay=grosspay+salary;
if (salary>=1000&&dependents<=2)
{
taxes=(grosspay*.15)+150;
}
if (salary>=1000&&dependents>2)
{
taxes=(grosspay*.125)+150;
}
else
{
taxes=0;
}
netpay=salary-taxes;
printf("Gross salary is: %f ",grosspay);
printf("Taxes withheld: %f ",taxes);
printf("Net salary after taxes is: %f ",netpay);
}
return 0;
}
Explanation / Answer
#include<stdio.h>
#include<math.h>
int main(void)
{
int dependents, netpay, taxes, employees, hoursworked;
double grosspay=0, rate=0, salary=0;
while (hoursworked>=0)
{
printf("Enter # of hours worked( -1 to end): ");
scanf("%d",&hoursworked);
printf("Enter hourly rate of pay: ");
scanf("%f",&rate);
printf("Enter number of dependents: ");
scanf("%d",&dependents);
employees++;
if(hoursworked<=40)
{
salary=(hoursworked*rate);
}
else
{
salary=(40*rate)+((hoursworked-40)*(1.5*rate));
}
grosspay=grosspay+salary;
if (salary>=1000&&dependents<=2)
{
taxes=(grosspay*.15)+150;
}
if (salary>=1000&&dependents>2)
{
taxes=(grosspay*.125)+150;
}
else
{
taxes=0;
}
netpay=salary-taxes;
printf("Gross salary is: %f ",grosspay);
printf("Taxes withheld: %f ",taxes);
printf("Net salary after taxes is: %f ",netpay);
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.