【发布时间】:2020-11-09 19:12:00
【问题描述】:
我正在编写一个程序,询问工作时间和工资率,然后计算他们的收入。如果这个人工作超过 40 小时,他们就会开始赚取加班费。
如何让它显示最多 40 小时的总收入,不包括加班费? "salary=hours<=40*rate;" 以 1 美元的价格返回。任何帮助将不胜感激!
#include <stdio.h>
int main(void)
{
int hours;
float rate,salary,totalPay, tax, netPay, overtime;
printf("Enter # of hours worked: ");
scanf("%d",&hours);
printf("Enter hourly rate of the worker: ");
scanf("%f",&rate);
if (hours>40)
{
salary=hours<=40*rate;
overtime=(hours-40)*rate*1.2;
printf("Salary is $%.2f\n",salary);
printf("overtime is $%.2f\n",overtime);
}
else
{
salary=hours*rate;
printf("Salary is $%.2f\n",salary);
printf("No overtime has been earned\n");
}
totalPay=salary+overtime;
printf("The total pay is $%.2f\n",totalPay);
tax= totalPay*.25;
printf("The amount of tax deducted is $%.2f\n",tax);
netPay=totalPay-tax;
printf("The net pay is $%.2f\n",netPay);
return 0;
}
【问题讨论】:
-
嗨。欢迎来到堆栈溢出。您能否编辑您的问题以提供最小可重复的示例?例如,可以编译的最小工作代码?有一些歧义(比如变量的数据类型)
-
salary=hours<=40*rate;-->salary=40*rate; -
这太简单了,我什至没有想到!我倾向于过度思考事情。非常感谢您的帮助!
标签: c if-statement numeric