### How is writing this question??

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)

I am a beginner in c++
Started? post what you've done so far.

Aceix.
 ``12345678910111213141516171819202122232425262728293031323334`` ``````#include using namespace 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="<3) pay+=10\$ cout<<"dependents"<

I know that the solution is incorrect and has its glitches
Possible help me
Does the problem want you to calculate the pay for a whole year or for just a month?

i thank pay for month
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...

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455`` ``````//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 ``````
 ``123456789101112131415161718192021222324252627282930313233343536373839404142`` ``````#include using namespace std; int main(){ float hour=0; int hourly_rate; int dependent; float gross_pay; float overtime_rate; float overtime_hours; float hours_monthly; float Social_Security; const int regular_hour=160; cout<<"===============WELCOME===================="<<"\n"; cout<<"Enter The number of hours worked in month:"<<"\n"; cin>>hours_monthly; cout<<"Enter the hourly rate :"<<"\n"; cin>> hourly_rate; overtime_rate=hour*1.5; cout<<"Enter the number of dependents:"<<"\n"; cin>>dependent; if(hours_monthly<=regular_hour) hour=hours_monthly; else { overtime_hours=hours_monthly-regular_hour; hour=regular_hour;} gross_pay=hour*hourly_rate+overtime_hours*overtime_rate; Social_Security=gross_pay*0.06; if(dependent>3) dependent=dependent*10; else dependent=0; float net_pay=gross_pay-Social_Security-dependent; cout<<"gross pay="<
The overtime rate needs to multiply whatever was entered for the hourly rate - right now it's multiplying hour (which is initialized to 0).

 ``12`` ``````cin>> hourly_rate; overtime_rate=hour*1.5;``````
Topic archived. No new replies allowed.