1. Define a C function named computePoy that calculates and returns the total fu
ID: 3597306 • Letter: 1
Question
1. Define a C function named computePoy that calculates and returns the total function has two input parameters, both double: worked by the person that week ), and the base pay rate per hour (let's call that r). The total pay for the week is calculated as follows the total number of hours payor inndvibal. Thi. urs h is less than O 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 40 tatement for this function from the following possible choices: 2. Circle the letter of an appropriate prototype st a. double computePay (h,r) b. int computePay (h, r, p): c. void computePay (double h, double r); d. int computePay (double a, double b, int c ) e. double computePay (double a, double b) Write the C statements that could be added to the main function to declare two variables and assign to them the values of some number of hours worked and the base hourly pay rate for an individual. Call the computePay function, passing the variables as arguments. (Walk through your function code and make sure it works correctly for 42 hours and 25 hours, as well as a value that would be considered an error 3.Explanation / Answer
1)
double computePay(double h,double r)
{
if (h<=0.0 || h>100.0)
{
return 0.0;
}else if(h==40.0)
{
return h*r;
}else
{
double d=h-40.0;
double k=40*r;
double t=d*1.5*r;
return (k+t);
}
}
2)e
base hourly rate may contains some fractional part so we can considered it as double
hours can be int or double .
it definitely return a fractional part if any of the two varibales contains fractional part.
wrong anwsers:a,b,c,d as these options are not according to the specification
b)doo
c)
#include <stdio.h>
double computePay(double h,double r)
{
if (h<=0.0 || h>100.0)
{
return 0.0;
}else if(h<=40.0)
{
return h*r;
}else
{
double d=h-40.0;
double k=40*r;
double t=d*1.5*r;
return (k+t);
}
}
int main(void) {
// your code goes here
double a,b;
a=42;b=10; printf("%f ",computePay(a,b));
a=25;b=10; printf("%f ",computePay(a,b));
a=101;b=10; printf("%f ",computePay(a,b));
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.