Function Practice 1. Define a C function named computePay that calculates and re
ID: 3596030 • Letter: F
Question
Function Practice 1. Define a C function named computePay that calculates and returns the total weekly pay for an individual. This function has two input parameters, both double: the total number of hours worked by the person that week (let's call that h), and the base pay rate per hour (let's call that r). The total pay for the week is calculated as follows: e If total hours h is less than 0 or more than 100, that is clearly a data entry error, and the function should return a value of 0.0 The individual is paid the base hourly rate, r, for each of the first 40 hours. The individual is paid 1.5 times the base rate for all hours above 40Explanation / Answer
#include <stdio.h>
double computePay(double h, double r) {
double total = 0;
if(h < 0 || h > 100) {
return total;
} else {
if(h > 40) {
total = (h - 40) * 1.5 * r;
h = 40;
}
total = total + (h * r);
return total;
}
}
int main()
{
double h,r;
printf("Enter the hours: ");
scanf("%lf", &h);
printf("Enter the rate: ");
scanf("%lf", &r);
printf("Pay: %lf ",computePay(h,r) );
return 0;
}
Output:
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.