230k views
4 votes
Write a code the estimates a worker’s weekly salary. The worker gets paid $12/hour. However, if they work over time (greater than 40 hours), the worker gets paid time and a half for any of the hours over 40 (e.g. if they wor ked 45 hours a week, they would get paid for 47.5 hours). However, the company has a policy that the worker cannot work more than 60 hours. Therefore, in the case of working greater than 60 hours, their salary gets capped at 60 hours. Your program shoul d input the number of hours worked in a week and should output their weekly salary (in whatever format that clearly shows the result)

1 Answer

4 votes

Answer:

The C program is commented in the explanation

Step-by-step explanation:

I am going to write a C program.

/*The number of hours worked is an input*/

void weeklyPay(int hours){

float Pay;

/*If he works 40 or less hours, he is paid $12 an hour*/

if(hours <= 40)

Pay = 12*hours;

/*If it is between 40 and 60, he gets 12 an hour plus time and a half over 40*/

if(hours >= 40 && hours <= 60)

Pay = 12*(hours + 1.5*(hours-40));

/*Else he gets paid what he would if he worked 60 hours*/

else

Pay = 12*(60 + 1.5*(60-40));

/*Output*/

printf("Weekly pay: %.2f\\", Pay);

}

User Victor Radu
by
6.0k points