Is this correct? Instructor says I'm calculating overtime wrong.

Feb 12, 2015 at 3:04am
So, we are working on a program to calculate taxes. Everything was fine except he said I calculated overtime wrong. All the math I've checked multiple times says I'm right. Can anyone point out what I'm calculating wrong or am I actually right?

overtime rate is 1.5 pay rate for all time over 40 hours.
simplified version, skipping a bunch of unrelated code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
double rate;
double orate;

double hours;
double ohours;

double gpay;

cin >> hours;
cin >> rate;

orate = rate * 1.5;

if (hours > 40) //set gpay if overtime or not
{
	ohours = hours - 40;
	
	gpay = (40 * rate) + (ohours * orate);
}
else
{
	gpay = hours * rate;
}
Last edited on Feb 12, 2015 at 3:05am
Feb 12, 2015 at 3:15am
closed account (2UD8vCM9)
Looks right to me?
Feb 12, 2015 at 3:18am
Looks good to me.
Feb 12, 2015 at 3:30am
That's what I thought. Will go ahead and use this again is this payroll program we are making and talk to him about getting those 10 points added back to my other assignment.

Thank you. :D
Topic archived. No new replies allowed.