我很难在计算每小时的每周薪水时弄清楚我的这个守则
#include <stdio.h>
int main() {
const int a = 1200;
int b = 40;
int c = 250;
int hour;
printf("Enter total hours\n");
scanf("%d", &hour);
switch(hour){
case 1:
if(hour==40)
printf("Your week pay is:%d.\n",a);
break;
case 2:
if(hour>40)
printf("Your week pay is: %d.\n", (hour-40)*b);
break;
case 3:
if(hour>55)
printf("Your week pay is: %d.\n", a+((hour-40)*b)+c);
break;
}
return 0;
}
我正在计算每小时员工的每周薪水,该员工的常规小时费率为30美元,加班费为40美元。前40个小时使用常规费用支付,然后使用加班费用支付后续时间。还有危险工资,当员工工作超过55小时时,他们的额外费用为250美元。
#include <stdio.h>
int main() {
const int a = 1200;
int b = 40;
int c = 250;
int hour;
printf("Enter total hours\n");
scanf("%d", &hour);
switch(hour){
case 1:
if(hour==40)
printf("Your week pay is:%d.\n",a);
break;
case 2:
if(hour>40)
printf("Your week pay is: %d.\n", (hour-40)*b);
break;
case 3:
if(hour>55)
printf("Your week pay is: %d.\n", a+((hour-40)*b)+c);
break;
}
return 0;
}
I'm computing for weekly salary for an hourly employee, the employee have a regular hourly rate of $30 and have an overtime rate of $40. The first 40 hours are paid using regular rate and the succeeding hours are paid using the overtime rate. There is also the hazard pay which when the employee works more than 55 hours their is additional $250.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
无需使用Switch语句。
您的代码永远不会显示任何输出。
如果/else ,则可以使用
,如果/else
。因此,删除交换机语句,然后尝试以下操作:There is no need to use a switch statement.
Your code will never show any output.
You can use
if/else
if/else if/else
. So, remove the switch statement and Try this:数学?
这是该程序正在尝试做什么;无论如何,它都不会起作用,因为它以给定的形式不正确。给出了逐步速率线性函数。给定的
y
,付款金额和x
,工作时间,应该:从问题中,案例为:0h&lt; = x&lt; = 40h,40h&lt; X&lt; = 55h,55h&lt; x。明显的角案例是0h,40h和55h,至少应该事先在纸上找出测试程序(我以41h,56h和60h的速度投掷)。可能会有所帮助。
将其放入程序中
switch
语句是不合适的,因为这是测试平等;这是一系列值,因此如果块,这将更适合作为一系列。由于值单调增加,因此可以建立薪水,
或者,正如您所注意到的,40h付款的部分超过40h,可以使用积分,
$ 30/h * 40h =将案例分开。 $ 1200
,并使用移位x
直接进行计算。Math?
This is what the programme is attempting to do; it will not work, anyways, because it is incorrect in it's given form. We are given a stepwise-rate linear function. Given
y
, the payment amount, andx
, the hours worked, It should:From the problem, the cases are: 0h <= x <= 40h, 40h < x <= 55h, 55h < x. Apparent corner cases are 0h, 40h, and 55h, at least, that one should figure out on paper beforehand to test this programme, (I'd throw in 41h, 56h, and 60h.) Doing a quick sketch of the graph on paper will probably be helpful.
Putting it into a programme
A
switch
statement is inappropriate because that's testing equality; this is a range of values, so this will be better suited to be a series ofif
blocks. Since the values are monotonically increasing, one could build up the pay,Or, as you have noticed, the section of 40h pay is a constant over 40h, one can separate the cases using the integral,
$30/h * 40h = $1200
, and calculate it directly using a shiftedx
.