Need help

I hva a program that i need help wtih. i made a program that will take the number of hours worked in a week and the number of dependents as inputs and then outputs the workers gross pay, each witholding amount, and the net take home pay per week. the person worked 34 hours out of 40 hours which is full.
9.50 and hour 6% withheld for state income tax, 14% withheld from federal income, 5% withheld from state income, $ 6 withheld for union dues. and if the person has three or more covered depedent, 10 additianal dollars is with held and the person has 2.
net take home pay should be 236.25

please not im still a beginner

heres my program

#include <iostream>
#using namespace std;

int main ()
{
int regHours; // Regular Hours
float hourlyPay, gross, otime, socialtax, federaltax, statetax, uniondue, dep, health; // gross income, overtime, social tax, federal tax, state tax, union due, depen covered, health insurance
double opay, sopay, fpay, spay, unpay, deppay, healthpay. netpay; // overtime scoial federal state union dependents and health withholdings including netpay

// Loop to do everything
{
cout << "Hello Employee" << endl;

cout << "Enter hours you have worked: ";
cin >> regHours;

cout << "Enter hourly pay rate: $";
cin >> hourlyPay;

cout << "Enter overtime rate: " ;
cin >> otime;

cout << "Enter percentage to be withheld for social security tax in decimal form: ";
cin >> socialtax;

cout << "Enter percentage to be withheld for federal income tax in decimal form: ";
cin >> federaltax;

cout << "Enter percentage to be withheld for state income tax in decimal form: ";
cin >> statetax;

cout << "Enter Union dues: ";
cin >> uniondues;

cout << "Enter number of dependents covered: ";
cin >> dep;

cout << "Enter additional health insurance expence: ";
cin >> health;


gross = regHours * hourlyPay; //Grosspay
opay = regHours * 1.5
if( regHours <= 40)
sopay = gross * socialtax; //Social income tax withholdings
fpay = gross * federaltax; //Federal income tax withholdings
spay = gross * statetax; //State withholdings
unpay = gross - uniondues; //Union Dues
deppay = gross - healthpay; //Number of dependents covered
healthpay = gross - health; //Addition health insurance expence
if( deppay >= 3 )
{
healthpay = gross - 10;
}
netpay = gross - opay - sopay - fpay - spay - deppay - healthpay; //Netpay

cout << "Weekly Report: \n\n";
cout << "Regular Hours: " << regHours << endl;
cout << "Gross Pay: $" << gross << endl;
cout << "Social income tax: $" << sopay << endl;
cout << "Federal income tax: $" << fpay << endl;
cout << "Union dues: $" << unpay << endl;
cout << "Number of dependents covered: $" << deppay << endl;
cout << "Additional health insurace expence: $" << healthpay << endl;
cout << "Net take home pay: $" << netpay << endl;

system("pause");
return 0;

}






can you tell me whats wrong with it?
Please use the code tags when writing out your code. It makes it much easier to read.

What output are you getting from your program?

If the user enters "14" as input for a percentage, you need to divide 14 by 100 to obtain the decimal form of the percentage. Doing Number - 14xNumber will give you a negative number, but doing Number-0.14xNumber will give you the amount left after 14% is withheld.
im only getting errors. would you like to copy and paste and see it? @JayZom
Last edited on
This might be it?
change #using namespace std; to using namespace std;
You don't need to use "#" when using a namespace.
i fixed that mistake. its still showing error messeges around where i had entered double
change healthpay. netpay; to healthpay, netpay;
You had a type o there.
over here im trying make the program calculate the number of hours the employee put which was overtime. the overtime hours was 1.5. but the employee has no overtime hours. but how to you make the program calculate the number of hours even if they dont have overtime

gross = regHours * hourlyPay; //Grosspay
opay = regHours * 1.5
if( regHours <= 40)
sopay = gross * socialtax; //Social income tax withholdings
fpay = gross * federaltax; //Federal income tax withholdings
spay = gross * statetax; //State withholdings
unpay = gross - uniondues; //Union Dues
deppay = gross - healthpay; //Number of dependents covered
healthpay = gross - health; //Addition health insurance expence
if( deppay >= 3 )
{
healthpay = gross - 10;
}
netpay = gross - opay - sopay - fpay - spay - deppay - healthpay; //Netpay
If overtime is any hours more than 40, you can try this:
1
2
3
//you could do this after gross = regHours * hourlyPay
if (regHours - 40 > 0)
     gross += (regHours - 40) * otime * hourlyPay;

You multiple "otime" and "hourlyPay" together to get the hourly rate for overtime hours (if they get $10 per hour for regular hours, then they would get 1.5*10 = $15 per hour for any hours over 40 hours).
If the employee doesn't have any overtime (didn't work more than 40 hours), then it wouldn't get added to "gross". Any overtime would only get added if they worked more than 40 hours, and it would only calculate the overtime for the number of hours over 40 (if they worked 45 hours, they would get 5 hours of overtime, and 5 hours of overtime would get added to gross pay).

If you do that, then you can get rid of if (regHours<=40) because the amount will be withheld regardless of how many hours the employee worked. The calculations for how much will be withheld should always be calculated, regardless of how many hours were worked.
gross = regHours * hourlyPay; //Grosspay
if (regHours - 40 > 0)
{
gross += (regHours - 40) * otime * hourlyPay;
}
opay = regHours * 1.5
sopay = gross * socialtax; //Social income tax withholdings
fpay = gross * federaltax; //Federal income tax withholdings
spay = gross * statetax; //State withholdings
unpay = gross - uniondues; //Union Dues
deppay = gross - healthpay; //Number of dependents covered
healthpay = gross - health; //Addition health insurance expence
if( deppay >= 3 )
{
healthpay = gross - 10;
}
netpay = gross - opay - sopay - fpay - spay - deppay - healthpay; //Netpay

now it shows an error messege at sopay
you forgot a semicolon after opay = regHours*1.5
Change it to opay = regHours*1.5;
closed account (48T7M4Gy)
float ... uniondues, not float uniondue
float ... uniondues, not float uniondue

Right, but a bit more of an explanation:
At the top of your code you wrote this:
1
2
float hourlyPay, gross, otime, socialtax, federaltax, statetax, uniondue, dep, health; // gross income, overtime, social tax, federal tax, state tax, union due, depen covered, health insurance 
double opay, sopay, fpay, spay, unpay, deppay, healthpay. netpay; // overtime scoial federal state union dependents and health withholdings including netpay  

but you wrote this later on
 
unpay = gross - uniondues; //Union Dues 

The two variable names for union dues don't match.
C++ will think they are different variables. Just change one of them (either remove the 's' from the first one, or add a 's' to the second one) so that they match.
theres one more error but i seem to not get it... can you ley me know what it is? it shows the error in the very last "{"

#include <iostream>
using namespace std;

int main ()
{
int regHours; // Regular Hours
float hourlyPay, gross, otime, socialtax, federaltax, statetax, uniondues, dep, health; // gross income, overtime, social tax, federal tax, state tax, union dues, depen covered, health insurance
double opay, sopay, fpay, spay, unpay, deppay, healthpay, netpay; // overtime scoial federal state union dependents and health withholdings including netpay

// Loop to do everything
{
cout << "Hello Employee" << endl;

cout << "Enter hours you have worked: ";
cin >> regHours;

cout << "Enter hourly pay rate: $";
cin >> hourlyPay;

cout << "Enter overtime rate: " ;
cin >> otime;

cout << "Enter percentage to be withheld for social security tax in decimal form: ";
cin >> socialtax;

cout << "Enter percentage to be withheld for federal income tax in decimal form: ";
cin >> federaltax;

cout << "Enter percentage to be withheld for state income tax in decimal form: ";
cin >> statetax;

cout << "Enter Union dues: ";
cin >> uniondues;

cout << "Enter number of dependents covered: ";
cin >> dep;

cout << "Enter additional health insurance expence: ";
cin >> health;


gross = regHours * hourlyPay; //Grosspay
{
gross += (regHours - 40) * otime * hourlyPay;
}
opay = regHours * 1.5;
sopay = gross * socialtax; //Social income tax withholdings
fpay = gross * federaltax; //Federal income tax withholdings
spay = gross * statetax; //State withholdings
unpay = gross - uniondues; //Union Dues
deppay = gross - healthpay; //Number of dependents covered
healthpay = gross - health; //Addition health insurance expence
if( deppay >= 3 )
{
healthpay = gross - 10;
}
netpay = gross - opay - sopay - fpay - spay - deppay - healthpay; //Netpay

cout << "Weekly Report: \n\n";
cout << "Regular Hours: " << regHours << endl;
cout << "Gross Pay: $" << gross << endl;
cout << "Social income tax: $" << sopay << endl;
cout << "Federal income tax: $" << fpay << endl;
cout << "Union dues: $" << unpay << endl;
cout << "Number of dependents covered: $" << deppay << endl;
cout << "Additional health insurace expence: $" << healthpay << endl;
cout << "Net take home pay: $" << netpay << endl;

system("pause");
return 0;

}
You're missing a '}' after
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Loop to do everything
{
cout << "Hello Employee" << endl;

cout << "Enter hours you have worked: ";
cin >> regHours; 

cout << "Enter hourly pay rate: $";
cin >> hourlyPay;

cout << "Enter overtime rate: " ;
cin >> otime;

cout << "Enter percentage to be withheld for social security tax in decimal form: ";
cin >> socialtax;

cout << "Enter percentage to be withheld for federal income tax in decimal form: ";
cin >> federaltax;

cout << "Enter percentage to be withheld for state income tax in decimal form: ";
cin >> statetax;

cout << "Enter Union dues: ";
cin >> uniondues;

cout << "Enter number of dependents covered: ";
cin >> dep;

cout << "Enter additional health insurance expence: ";
cin >> health;
//missing '}' here 

add a '}' after cin >> health;
I don't know if this has been mentioned but, unpay, deppay, healthpay. netpay; //
after
healthpay
there should be a comma not dot?

it has been mentioned, nvm.
Last edited on
the program runs now but i still dont know the formula to add the overtime which is 1.5 hours if it exceeded fulltime hours which is 40. and a formula for number of dependents of if it exceeded 3 it woukd deduct 10$ from the gross pay

#include <iostream>
using namespace std;

int main ()
{
int regHours; // Regular Hours
float hourlyPay, gross, otime, socialtax, federaltax, statetax, uniondues, dep, health; // gross income, overtime, social tax, federal tax, state tax, union dues, depen covered, health insurance
double opay, sopay, fpay, spay, unpay, deppay, healthpay, netpay; // overtime scoial federal state union dependents and health withholdings including netpay

// Loop to do everything
{
cout << "Hello Employee" << endl;

cout << "Enter hours you have worked: ";
cin >> regHours;

cout << "Enter hourly pay rate: $";
cin >> hourlyPay;

cout << "Enter overtime rate: " ;
cin >> otime;

cout << "Enter percentage to be withheld for social security tax in decimal form: ";
cin >> socialtax;

cout << "Enter percentage to be withheld for federal income tax in decimal form: ";
cin >> federaltax;

cout << "Enter percentage to be withheld for state income tax in decimal form: ";
cin >> statetax;

cout << "Enter Union dues: ";
cin >> uniondues;

cout << "Enter number of dependents covered: ";
cin >> dep;

cout << "Enter additional health insurance expence: ";
cin >> health;


gross = regHours * hourlyPay; //Grosspay
{
gross += (regHours - 40) * otime * hourlyPay;
}
opay = regHours * 1.5; //Over time hours
sopay = gross * socialtax; //Social income tax withholdings
fpay = gross * federaltax; //Federal income tax withholdings
spay = gross * statetax; //State withholdings
unpay = gross - uniondues; //Union Dues
deppay = gross - healthpay; //Number of dependents covered
healthpay = gross - health; //Addition health insurance expence
if( deppay >= 3 )
{
healthpay = gross - 10;
}
netpay = gross - opay - sopay - fpay - spay - deppay - healthpay; //Netpay

cout << "Weekly Report: \n\n";
cout << "Regular Hours: " << regHours << endl;
cout << "Gross Pay: $" << gross << endl;
cout << "Social income tax: $" << sopay << endl;
cout << "Federal income tax: $" << fpay << endl;
cout << "Union dues: $" << unpay << endl;
cout << "Number of dependents covered: $" << deppay << endl;
cout << "Additional health insurace expence: $" << healthpay << endl;
cout << "Net take home pay: $" << netpay << endl;

}

system("pause");
return 0;

}

mind you it got the calculations wrong
the program runs now but i still dont know the formula to add the overtime which is 1.5 hours if it exceeded fulltime hours which is 40. and a formula for number of dependents of if it exceeded 3 it woukd deduct 10$ from the gross pay


Can you do the calculations on your own with a calculator? Just write down every step you take in doing that and you have your algorithm.

If total hours were more than 40, you would find the difference between total hours and 40 to get overtime hours, then get the product of overtime hours and 1.5 to find overtime pay and add that to regular hours pay to get total pay..

The process for number of dependent deductions is almost identical to that. If total dependents are more than 3, find the difference between total dependents and 3, then (assuming you mean $10 per dependent) find the product of additional dependents and 10 and subtract that from the gross pay.
Topic archived. No new replies allowed.