有没有人可以解答一下这一道题 是c语言编程的一道题
Assumethatthevariablesrate_per_hrandtot_hrscontainanemployee'shourlyrateofpayandtotal...
Assume that the variables rate_per_hr and tot_hrs contain an employee's hourly rate of pay and total hours worked during the week. Use an if statement to calculate the employee's gross pay for the week, using the rule that the first 40 hours worked are paid at rate_pr_hr, and any time over 40 hours is paid at rate_pr_hr * 1.5.
展开
2016-08-13
展开全部
#include <stdio.h>
int main(void)
{
double rate_per_hr,tot_hrs,gross_pay;
scanf("%lf%lf",&rate_per_hr,&tot_hrs);
if(tot_hrs>40)
{
gross_pay=40*rate_per_hr+(tot_hrs-40)*rate_per_hr*1.5;
}
else
{
gross_pay=tot_hrs*rate_per_hr;
}
printf("%lf\n",gross_pay);
return 0;
}
更多追问追答
追问
大哥顺便问一下 这其实是一个问题来的 谢谢
Redo the above problem, but use conditional operators instead of the if statement.
追答
#include <stdio.h>
int main(void)
{
double rate_per_hr,tot_hrs,gross_pay;
scanf("%lf%lf",&rate_per_hr,&tot_hrs);
gross_pay=tot_hrs>40?40*rate_per_hr+(tot_hrs-40)*rate_per_hr*1.5:tot_hrs*rate_per_hr;
printf("%lf\n",gross_pay);
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |