Write a program called Program1 with a main method that asks the user for his or
ID: 3759548 • Letter: W
Question
Write a program called Program1 with a main method that asks the user for his or her pay rate and the number of hours he or she worked this week. Then the main method should call the following two methods and store the results it gets from each method. getTotalPay - takes two parameters, an integer for the number of hours worked and a double for the pay rate. If the number of hours is less than or equal to 40, it simply multiplies them together and returns the result. If the number of hours is greater than 40, he gets an additional dollar for each hour over 40 that he or she has worked. For example if the pay rate is $10 and someone worked 41 hours, they would get $411.00. getPercentage - takes one parameter - the number of hours worked, and returns the time worked as a percentage of 40 hours. For example, if the number of hours worked is 20, it should return 50.0. The main method also calls a third method which displays the results nicely on the screen. The third method, displayOutput, should have four parameters and should print the output as shown below (use printf). Pay Rate: $10.0 Hours Worked: 41 Percentage worked per week: 102.5% Total pay earned: $411.00
Explanation / Answer
#include <stdio.h>
float gettotalpay(int,float);
float getpercentage(int);
void displayoutput(int,float,float ,float);
int main(void) {
int nhr, temp;
float payrate, payearn, percentwork;
printf("enter no. of working hours");
scanf("%d",&nhr);
printf("enter payrate");
scanf("%f",&payrate);
payearn=gettotalpay(nhr,payrate);
percentwork=getpercentage(nhr);
displayoutput(nhr,payrate,payearn,percentwork);
return 0;
}
float gettotalpay(int nhr,float payrate)
{
int temp=nhr-40;
float amount=0;
if(nhr<=40)
amount=nhr*payrate;
else
amount=(nhr*payrate)+temp;
return amount;
}
float getpercentage(int nhr)
{
float time=0;
time=(nhr/40)*100;
return time;
}
void displayoutput(int nhr,float payrate,float payearn,float percentwork)
{
printf("Pay Rate:$ %f Hours Worked: %d Percentage worked per week: %f % Total pay earned: $ %f",payrate,nhr,percentwork,payearn);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.