编写一个程序,提示用户输入一周的工作小时数,然后打印工资总数、税金和净收入。做如下假设:

编写一个程序,提示用户输入一周的工作小时数,然后打印工资总数、税金和净收入。做如下假设:

a. 让程序可以给出一个供选择的工资等级菜单。使用switch完成工资等级选择。运行程序后,显示的菜单应该类似这样:


Enter the number corresponding to the desired pay rate or action:

1) $8.75/hr 2) $9.33 /hr

3) $10.00/hr                                          4) $11.20/hr

5) quit


如果选择1-4其中的一个数字,程序应该询问用户工作的小时数。程序要通过循环运行,除非用户输入5.如果输入1-5以外的数字,程序应提醒用户输入正确的选项,然后再重复显示菜单提示用户输入。使用#define创建符号常量表示各工资等级和税率。

b. 加班(超过40小时) = 1.5倍工作时间

c. 税率: 前300美元为15%

续150美元为20%

余下的为25%

以下为代码

#include <stdio.h>
#include <ctype.h>
#define BREAK1 300
#define BREAK2 450
#define base1 (BREAK1 * (1 - rate1))
#define base2 (base1 + (BREAK2 - BREAK1) * (1 - rate2))
#define rate1 0.85
#define rate2 0.8
#define rate3 0.75
#define basicincome1 8.75
#define basicincome2 9.33
#define basicincome3 10.00
#define basicincome4 11.20
#define extratime 40

int main(void)
{
	float worktime = 0.0;
	double totalincome = 0.0;
	int choice;
	
	printf("Enter the number corresponding to the desired pay rate or action:\n");
	printf("1) $8.75/hr                          2) $9.33/hr\n");
	printf("3) $10.00/hr                         4) $11.20/hr\n");
	printf("5) quit\n");
	scanf("%d",&choice);
	
	
	while(choice != 5)
	{
		if(choice > 5 || choice < 1)
	    {
		printf("please enter the right number:");
	    scanf("%d", &choice);
	    continue;
		}
		printf("Enter your work time per week: ");
	    scanf("%f", &worktime);
		switch (choice){
		case 1: if(worktime <= extratime)
		totalincome = worktime * basicincome1;
    	else
	    totalincome = (worktime - extratime) * 1.5 * basicincome1 + extratime * basicincome1;
	    break;
	    case 2: if(worktime <= extratime)
		totalincome = worktime * basicincome2;
    	else
	    totalincome = (worktime - extratime) * 1.5 * basicincome2 + extratime * basicincome2;
	    break;
	    case 3: if(worktime <= extratime)
		totalincome = worktime * basicincome3;
    	else
	    totalincome = (worktime - extratime) * 1.5 * basicincome3 + extratime * basicincome3;
	    break;
	    case 4: if(worktime <= extratime)
		totalincome = worktime * basicincome4;
    	else
	    totalincome = (worktime - extratime) * 1.5 * basicincome4 + extratime * basicincome4;
	    break;
        }    
	
	if(totalincome <= BREAK1)
	printf("your total income is %.2lf$, tax money is %.2lf$, and real income is %.2lf$", 
	totalincome, (1 - rate1) * totalincome, rate1 * totalincome);
	else if(totalincome > BREAK1 && totalincome <= BREAK2)
	printf("your total income is %.2lf$, tax money is %.2lf$, and real income is %.2lf$", 
	totalincome, (1 - rate2) * (totalincome - BREAK1) + base1, (totalincome - BREAK1) * rate2 + BREAK1 * rate1);
	else 
	printf("your total income is %.2lf$, tax money is %.2lf$, and real income is %.2lf$", 
	totalincome, (1 - rate3) * (totalincome - BREAK2) + base2, (totalincome - BREAK2) * rate2 + BREAK1 * rate1 + BREAK2 * rate3);
	
	printf("Enter the number corresponding to the desired pau rate or action:\n");
	printf("1) $8.75/hr                          2) $9.33/hr\n");
	printf("3) $10.00/hr                         4) $11.20/hr\n");
	printf("5) quit\n");
	scanf("%d",&choice);
    }
    printf("Done!\n");
	return 0;
}

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值