Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem 2 Write a function called calcPay which takes two floating point paramet

ID: 3750048 • Letter: P

Question

Problem 2 Write a function called calcPay which takes two floating point parameters (type double) representing the number of hours worked and an hourly pay rate. The function returns the calculated total pay. Hours worked over 40 hours (overtime hours) should be calculated at 1. the pay rate (time and a half). . Your function MUST be named calcPay. .Your function should take two parameters in this order: a floating point parameter for hours worked (type double) a floating point parameter for pay rate (type double) o o . Your function should return the total pay. For example, if someone worked 41 hours and their pay rate is $10 their total pay is $415. Regular Pay: (40 hours $10) Overtime Pay: (1 hours ($10 1.5)) $15 Total Pay: - $400 $415

Explanation / Answer


Given below is the code for the question.
Please do rate the answer if it was helpful. Thank you
double calcPay(double hoursWorked, double payRate){
if(hoursWorked < 0 || payRate < 0) //invalid input
return -1;
double regularPay = 0, overtimePay = 0, total = 0;
//overtime?
if(hoursWorked > 40){
regularPay = 40 * payRate;
overtimePay = (hoursWorked - 40) * payRate * 1.5;
}
else{ //only regular
regularPay = hoursWorked * payRate;
}
total = regularPay + overtimePay;
return total;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote