有没有人可以解答一下这一道题 是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;
}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式