1. ## my answer correct or not??

hello every body

this the question

An employee is paid at rate of 16.78\$ per hour for the first 40 hours worked in a week. Any hours over that are paid at the overtime rate of one and one half times that. From the worker's gross pay, 6% is witheld for social security tax, 14% is witheld for federal income tax, 5% is witheld for state income tax, and 10 dollars per week is witheld for union dues. If the worker has three or more dependents, then the additional 35 dollars is withheld to cover the extra cost of helf insurance beyond what the employer pays. Write the program that will read in the number of hours worked in a week and the number of dependents as input, and will then output the worker's gross pay , each witholding amount , and the net take home pay for the week. For the harder version , write your program so that it allows the calculation to be repeated as often as the user wishes.

but i don't know if true or false

Code:
```#include <iostream>
using namespace std;
int main()
{
const double rate=16.78;
const double social_tax= 0.06;
const double federal_tax=0.14;
const double state_tax=0.05;
int hours,dependents;
double net_pay,gross_pay,overtime,state_tax_pay,pay_overtime,social_tax_pay,federal_tax_pay;
cout<<"how many hours you worked this week: (0 to exit) ";
cin>>hours;
while (hours>0)
{
cout<<"How many children you have?: ";
cin>>dependents;
if(hours>40)
{
if (dependents>=3)
{
overtime=hours-40;
pay_overtime=overtime*(rate*1.5);
gross_pay= (rate*hours)+pay_overtime;
social_tax_pay=gross_pay*social_tax;
cout<<"Your sosial tax pay is equal to: "<<social_tax_pay<<endl;
federal_tax_pay=gross_pay*federal_tax;
cout<<"Your federal tax pay is equal to: "<<federal_tax_pay<<endl;
state_tax_pay=gross_pay*state_tax;
cout<<"Your state tax pay is equal to: "<<state_tax_pay<<endl;
cout<<"You have to pay additional 35\$ becouse you heve more then two dependends\n";
net_pay=gross_pay-social_tax_pay-federal_tax_pay-state_tax_pay-35;
cout<<"Your net pay is equeall to: "<<net_pay;
}
else
{
overtime=hours-40;
pay_overtime=(rate*1.5)*overtime;
gross_pay= (rate*hours)+pay_overtime;
social_tax_pay=gross_pay*social_tax;
cout<<"Your sosial tax pay is equal to: "<<social_tax_pay<<endl;
federal_tax_pay=gross_pay*federal_tax;
cout<<"Your federal tax pay is equal to: "<<federal_tax_pay<<endl;
state_tax_pay=gross_pay*state_tax;
cout<<"Your state tax pay is equal to: "<<state_tax_pay<<endl;
net_pay=gross_pay-social_tax_pay-federal_tax_pay-state_tax_pay;
cout<<"Your net pay is equeall to: "<<net_pay;

}
}
else
{
if (dependents>=3)
{
gross_pay= rate*hours;
social_tax_pay=gross_pay*social_tax;
cout<<"Your sosial tax pay is equal to: "<<social_tax_pay<<endl;
federal_tax_pay=gross_pay*federal_tax;
cout<<"Your federal tax pay is equal to: "<<federal_tax_pay<<endl;
state_tax_pay=gross_pay*state_tax;
cout<<"Your state tax pay is equal to: "<<state_tax_pay<<endl;
cout<<"You have to pay additional 35\$ becouse you heve more then two dependends\n";
net_pay=gross_pay-social_tax_pay-federal_tax_pay-state_tax_pay-35;
cout<<"Your net pay is equeall to: "<<net_pay;
}
else
{
gross_pay= rate*hours;
social_tax_pay=gross_pay*social_tax;
cout<<"Your sosial tax pay is equal to: "<<social_tax_pay<<endl;
federal_tax_pay=gross_pay*federal_tax;
cout<<"Your federal tax pay is equal to: "<<federal_tax_pay<<endl;
state_tax_pay=gross_pay*state_tax;
cout<<"Your state tax pay is equal to: "<<state_tax_pay<<endl;
net_pay=gross_pay-social_tax_pay-federal_tax_pay-state_tax_pay;
cout<<"Your net pay is equeall to: "<<net_pay;
}
}

cout<<endl;
cout<<"how many hours you worked this week: (0 to exit)";
cin>>hours;

}
return 0;

}```

2. True or false ? This is not about being true or false but rather being correct or not. This is not even about being correct or not, but rather about producing the expected results or not. Does it output the expected results ? Then your code is fine.

3. Originally Posted by Desolation
True or false ? This is not about being true or false but rather being correct or not. This is not even about being correct or not, but rather about producing the expected results or not. Does it output the expected results ? Then your code is fine.

and sorry about my poor english.

4. Your code is fine, I have tried it out, the only problems I see are some spelling issues.

Sosial should be Social
Equall should be Equal
becouse should be because
Dependends should be Dependents

That is all, good luck..

5. This calculation is wrong:
Code:
```overtime=hours-40;
pay_overtime=overtime*(rate*1.5);
gross_pay= (rate*hours)+pay_overtime;```
When you've worked overtime, the amount of hours over 40 gets the time-and-a-half pay rate (that's done correctly). The other 40 hours worked gets the normal pay rate but you haven't adjusted hours to take that into account. You're calculating based on the original (over 40) hours worked and you'll end up paying the worker more than what is deserved. You need to either cap hours at 40 or just use a hard-coded 40 value there in place of hours, i.e.:
Code:
`gross_pay= (rate*40)+pay_overtime;`

Other than that, there is a lot of duplicated code there that can be combined.

6. Code:
```overtime=hours-40;
pay_overtime=overtime*(rate*1.5);
gross_pay= (rate*hours)+pay_overtime;```
What if you didn't work overtime? You'll end up with a negative value here

7. Originally Posted by h_howee
What if you didn't work overtime? You'll end up with a negative value here
That's part of an if block that takes care of that:
Code:
```if(hours>40)
{
if (dependents>=3)
{
overtime=hours-40;
pay_overtime=overtime*(rate*1.5);
gross_pay= (rate*hours)+pay_overtime;
...
}
else
{
overtime=hours-40;
pay_overtime=overtime*(rate*1.5);
gross_pay= (rate*hours)+pay_overtime;
...
}```