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.
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
32
33
34
#include <iostream>
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="<<pay;
	 cout<<"\n";
	 else if(hourly_ratr)
		 hourly_ratr=hourly_rate*360/12;
	 cout<<"hourlu rate ="<<hourly_ratr<<"\n";
	 else if(dependents>3)
		 pay+=10$
		 cout<<"dependents"<<pay<<"\n";
	 else if(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
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...

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//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 
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
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
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="<<gross_pay<<"\n";
	cout<<"Social Security="<<Social_Security<<"\n";
	cout<<"dependent="<<dependent<<"\n";
	cout<<"net pau"<<net_pay<<"\n";
	
		system("PAUSE"); 
       return 0; 
}
The overtime rate needs to multiply whatever was entered for the hourly rate - right now it's multiplying hour (which is initialized to 0).

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