Write a program that calculates for an employee the gross pay and net pay , given the number of hours worked by an employee, hourly rate and the number of dependents of the employee.
The output should include the employee's gross pay , each amount deducted, and his net pay. Gross pay should be calculated according to :
Regular hours are : 160 hours per month ( Declare regular hours as const )
Overtime rate (if there are extra hours) : one and a half times as much as the hourly rate
Deductions :
Social security : 6%
Number of dependents more than 3 : $ 10
( use conditional operators whenever possible)
#include <iostream>
usingnamespace std;
int main(){
int hour_work;
int hourly_rate;
int dependents;
int Social_Security;
int pay;
cout<<"===============WELCOME===================="<<"\n";
cout<<"Enter The number of hours worked:"<<"\n";
cin>>hour_work;
cout<<"Enter the hourly rate :"<<"\n";
cin>> hourly_rate;
cout<<"Enter the number of dependents:"<<"\n";
cin>>dependents;
cout<<"Is there a social security?"<<"\n"
<<"if you have pout 1 and if uou not have pout 0"<<"\n";
if(hour_work==160)
pay=360*hour_work/8;
cout<<"pay="<<pay;
cout<<"\n";
elseif(hourly_ratr)
hourly_ratr=hourly_rate*360/12;
cout<<"hourlu rate ="<<hourly_ratr<<"\n";
elseif(dependents>3)
pay+=10$
cout<<"dependents"<<pay<<"\n";
elseif(Social_Security==1)
pay -=6%
cout<<"Social Security="<<pay<<"\n";
else
system("PAUSE");
return 0;
}
I know that the solution is incorrect and has its glitches
Possible help me
The social security looks like it's just a flat percentage rate of the gross pay, so I don't think you need to ask the user to input anything for that. With C++ though, you need to translate the 6% you're given in the problem to a format the program will understand ( .06 ) Similarly you'll need to use something other than the literal 10$ given in the problem when you calculate in C++.
I'd rethink the current if... else selection structure. Right now, if the person has worked a regular month of 160 hours, you won't get to any of the code that tries to print out dependent and social security deductions.
You could break the main function down into steps something like this...
//Declare variables
//include a constant variable for regular hours initialized to 160
//you could also consider using a constant variable for the social
//security percentage initialized to .06
//remember some variables should be double, not int, since they will probably be holding values
//with a floating point, e.g. a pay rate that is not a whole dollar amount
//input hours, rate and dependent info
Input hours worked in the month (monthly hours)
Input hourly rate (hourly rate)
Calculate overtime rate (hourly rate * 1.5)
Input number of dependents (dependents)
//Determine hours to be paid
if monthly hours is less than or equal to regular hours constant
// they didn't work overtime
hours = monthly hours //hours to be paid at regular rate are what was entered by user
else // they did work overtime
//remember to put an opening and closing brace { }
//around multiple statements to be run
{
overtime hours = monthly hours - regular hours constant
// overtime equals hours entered less the hours paid at regular rate
hours = regular hours constant
// hours paid at regular rate equals the regular hours constant
}
//Calculate gross pay
gross pay = hours * hourly rate + overtime hours * overtime rate
//Calculate social security deduction
social security deduction = gross pay * .06
// (or gross pay * constant variable for social security rate if you use that)
//Determine any deduction for extra dependents
if dependents is greater than 3,
dependent deduction = # of dependents over 3 * 10
else
dependent deduction = 0 // no dependent deduction
//Calculate net pay
net pay = gross pay - social security deduction - dependent deduction
//Output
Output gross pay
Output social security deduction
Output dependent deduction if it exists
Output net pay