#include <stdio.h> //#define GRAND 10.00 #define TIME 40//超过40小时为加班 #define OVERTIME 1.5//加班的时间按1.5倍计算 #define A_TAX 300 //税率 前300美元为15% #define B_TAX 150 // 下一个150美元为20% #define A_RATE 0.15 // 余下的为25% #define B_RATE 0.20 // #define C_RATE 0.25 // int get_int(void); int main(int argc, const char * argv[]) {
float times,basic,salary=0,taxes=0,net_pay=0;
printf("Enter the number corresonding to the desired pay rate or action:\n");
printf("1)$8.75/hr\t\t\t2)$9.33/hr\n"); printf("3)$10.00/hr\t\t\t4)$11.20/hr\n"); printf("5)quit\n");
switch (get_int()) { case 1: basic=8.75; break;
case 2: basic=9.33; break;
case 3: basic=10.00; break;
case 4: basic=11.20; break;
default: printf("quit\n"); return (0);//退出程序 }
printf("You have select $%.2lf\n",basic);
printf("请输入你一周的工作时间:");
scanf("%f",×);
if (times>=0){
if (times<=TIME) { //没有加班
salary=times*basic;
if (salary<=300) { taxes=salary*A_RATE; net_pay=salary-taxes; } if (salary>300) { taxes=300*A_RATE+(salary-300)*B_RATE; net_pay=salary-taxes; }
}else{ //加班后
salary=(TIME+(times-TIME)*OVERTIME)*basic;
if (salary<=A_TAX+B_TAX) { taxes=A_TAX*A_RATE+(salary-A_TAX)*B_RATE; net_pay=salary-taxes; }else { taxes=A_TAX*A_RATE+B_TAX*B_RATE+(salary-A_TAX-B_TAX)*C_RATE; net_pay=salary-taxes; } }
printf("您的薪资为%.2f,交税%.2f,净工资%.2f.\n",salary,taxes,net_pay);
}else
printf("您的输入有误。。。\n");
return 0; } int get_int(void){//得到一个合适的数,滤除非法数
int num; char str[40]; while (scanf("%d",&num)!=1) {
gets(str); printf("error!%s is not an number.input again.\n",str); } while (getchar()!='\n') ; return num;
}
|