Problem with solving This Question.

Sample output :

Enter employee's grade(A,B,C or D):f
Enter employee's grade(A,B,C or D):a
Enter the total number of working hour : 198
Normal pay 1683.00
OT pay 0.00
Total pay 1683.00

output 2:
Enter employee's grade(A,B,C or D):B
Sample output :

Enter employee's grade(A,B,C or D):f
Enter employee's grade(A,B,C or D):a
Enter the total number of working hour : 198
Normal pay   1683.00
OT pay          0.00
Total pay    1683.00

output 2:
Enter employee's grade(A,B,C or D):B
Enter the total number of working hour : 205
Normal pay   1500.00
OT pay         56.25
Total pay  1556.25

Condition:
any employee work more than 200 hours is entitled to an overtime pay of 1.5 times than normal pay. Declare 200hours and 1.5times as constants.

GRADE (A : 8.5 B:7.5 C:6.5 D:5.0)

accept both uppercase and lowercase of the grade

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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include<iostream>
#include<iomanip>
#include<cmath>

using namespace std;
int main()
{
	char grade;
	double a=8.5,b=7.5,c=6.5,d=5.0;
	double normal=0,overtimepay=0;
	double overtimefactor=1.5;
	double total=0;
	int hour=200;

	do
	{
		cout<<endl;
		cout<<"A. 8.5"<<endl;
		cout<<"B. 7.5"<<endl;
		cout<<"C. 6.5"<<endl;
		cout<<"D. 5.0"<<endl;
		cout<<"Enter emloyee's grade (A, B, C or D): ";
		cin>>grade;

	if(!(grade=='A' || grade=='a' || grade=='B' || grade=='b' || grade=='C' || grade=='c' || grade=='D' || grade=='d'))
	{
		cout<<"Invalid Grade! Please re-enter employee's grade (A, B, C or D): ";
		cin>>grade;
	}

		cout<<"Enter total number of working hour: ";
		cin>>hour;

	if(hour>200)
	{
		overtimepay= ((normal-(200*b)) * overtimefactor);
	}
	else if(hour<200)
	{
		overtimepay=0;
	}

	if(grade=='A' || grade=='a')
   {
	 normal=a*hour;
	 total=overtimepay+normal;
   }
   if(grade=='B' || grade=='b')
	{
	 normal=b*hour; 
	 total=overtimepay+normal;
	}
	if (grade=='C' || grade=='c')
	{
	 normal=c*hour;
	 total=overtimepay+normal;
	}
   if( grade=='D' || grade=='d')
	{
     normal=d*hour;
	 total=overtimepay+normal;
	}
	cout<<"Normal pay"<<right<<setw(10)<<fixed<<setprecision(2)<<normal<<endl;
	cout<<"OT pay"<<right<<setw(14)<<fixed<<setprecision(2)<<overtimepay<<endl;
	cout<<"Total pay"<<right<<setw(11)<<fixed<<setprecision(2)<<total<<endl;
	}while(!(grade=='A' && grade=='a' && grade=='B' && grade=='b' && grade=='C' && grade=='c' && grade=='D' && grade=='d'));

	system("Pause");
	return 0;
}


There is an error with hour>200. it seems that it does not get what the example 2 from the output given. I try many ways to solve it. im a beginner. Much appreciate for the guidance and advice. Thank you.

the problem i think is come with this
if(hour>200)
{
overtimepay= ((normal-(200*b)) * overtimefactor);
}
Last edited on
1. Seems like your formula to calculate overtime is wrong. Since normal is initially set to 0 and you are subtracting (200*b) from normal, the number would always be negative.
The correct equation should be

overtimepay = (hour - 200)*(1.5 * normal_pay_per_hour);

2. Also, you are calculating overtime pay only for B. What if the employees of other grades work overtime.


According to me

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
if(grade == "A" || grade == "a")
{
     if(hour > 200)
     {
            overtimepay = (hour - 200)*(1.5 * a);
            normal = 200*a;
     }
     else
     {
            normal = hour*a;
            overtime = 0;
     }

     totalpay = normal + overtime;


}



Similarly, repeat for other grades with corresponding grade pay
Okay. THANKS! i solved it :D
Topic archived. No new replies allowed.