BEGINNER HERE

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
71
72
73
#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<<"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(grade=='A' || grade=='a')
{
	 normal=a*hour;
	 overtimepay= ((normal-(200*a)) * overtimefactor);
	 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;
    }
	else if(grade=='B' || grade=='b' || hour>200)
	{
	 normal=b*hour;
	 overtimepay= ((normal-(200*b)) * overtimefactor);
	 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;
	}
	else if (grade=='C' || grade=='c')
	{
	 normal=c*hour;
	 overtimepay= ((normal-(200*c)) * overtimefactor);
	 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;
	}
    else if( grade=='D' || grade=='d')
	{
     normal=d*hour;
	 overtimepay= ((normal-(200*d)) * overtimefactor);
	 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 problem with the overtime pay and how to count overtime pay if hour less than 200 hour and more than 200 hour. Please help
Last edited on
Hello desmondlee95,

Keep in mind that you do not have to calculate overtime pay each time. Only on the hours above 200.

I just played with A for now and all I did was add the lineif(hour > 200) before the calculation for overtimepay. And after all the if statements I added overtimepay = 0 just to be safe. Adding the if statement to the rest of the pay grades should take care of your overtime pay problem.

When I tested the second example normal pay was not correct. Example says normal pay = 1500, but the program spit out 1537. I found that the linenormal=a*hour; hour was 205 when it should be 200 at this point. Hour having value of 205 works well in the overtimepay calculation, but not for normal pay.

Hope that helps,

Andy
That helps alot. i fixed the if(hour>200) . Thank you !

( When I tested the second example normal pay was not correct. Example says normal pay = 1500, but the program spit out 1537. I found that the linenormal=a*hour; hour was 205 when it should be 200 at this point. Hour having value of 205 works well in the overtimepay calculation, but not for normal pay. ) for this :

is there any calculation for this ? i seem cant figure out the second example calculation

Last edited on
Topic archived. No new replies allowed.