练习四

来源:互联网 发布:java工程师好找工作吗 编辑:程序博客网 时间:2024/04/30 11:45

/*编写一个程序,提示用户输入一周的工作小时数,然后打印工资总数,税金和净收入
  a.基本工资=1000美元/小时
  b.加班(超过40小时)=1.5倍的时间
  c.税率: 前300元为15%
     续150美元为20%
     余下的为25%
*/

自己写程序还是太粗心,竟然忘了&,还找了好长时间。还是要认真,加油。

如下:

/*编写一个程序,提示用户输入一周的工作小时数,然后打印工资总数,税金和净收入  a.基本工资=1000美元/小时  b.加班(超过40小时)=1.5倍的时间  c.税率: 前300元为15%   续150美元为20%   余下的为25%*/#include<stdio.h>#define FIRST 0.15#define  TWO  0.20#define THIRD 0.25int main(){float wtime=0;float num=0;float tax=0;float net_value=0;printf("please imput a week working time:\n");scanf("%f",wtime);if(wtime<0)printf("sorry,please enter a number greater than zero:\n");else{num=1000*wtime;   //总值    printf("%f",num);}if(num<=300)tax=FIRST*wtime;   //税金else if(wtime<=450)tax=TWO*(wtime-300);else if(wtime>450)tax=THIRD*(wtime-450);net_value = num - tax; //净值printf("num=%f\n,tax=%f\n,net value=%f\n",num,tax,net_value);return 0;}

查出错误后:

/*编写一个程序,提示用户输入一周的工作小时数,然后打印工资总数,税金和净收入  a.基本工资=1000美元/小时  b.加班(超过40小时)=1.5倍的时间  c.税率: 前300元为15%   续150美元为20%   余下的为25%*/#include<stdio.h>#define FIRST 0.15#define  TWO  0.20#define THIRD 0.25int main(){float wtime=0;float num=0;float tax=0;float net_value=0;printf("please imput a week working time:\n");scanf("%f",&wtime);if(wtime<0)printf("sorry,please enter a number greater than zero:\n");else{num=1000*wtime;   //总值    printf("%f",num);}if(num<=300)tax=FIRST*wtime;   //税金else if(wtime<=450)tax=TWO*(wtime-300);else if(wtime>450)tax=THIRD*(wtime-450);net_value = num - tax; //净值printf("num=%f\n,tax=%f\n,net value=%f\n",num,tax,net_value);return 0;}


原创粉丝点击