c primer plus第六版第七章编程练习

//习题八
#include<stdio.h>
#include<stdlib.h>
#define first_tax 0.15
#define second_tax 0.2
#define last_tax 0.25
#define A 8.75
#define B 9.33
#define C 10.00
#define D 11.20
#define E "quit"

void exit(int value);

void main()
{
	float Allmoney,hours,tax,realmoney;
	int i,j;

	while(1)
	{
	for(i=1;i<20;i++)
		printf("*");
	printf("\n");
	printf("Enter the number corresponding to the desired pay rate or action:\n");
	printf("1)$%.2f\\hr \t 2)$%.2f\\hr \n3)$%.2f\\hr \t 4)$%.2f\\hr \n5)$%s\\hr \n",A,B,C,D,E);
	for(i=1;i<20;i++)
		printf("*");
	printf("\n");
	while(1)
	{
		scanf("%d",&j);
		if(j>=1 && j<=4)
		{
		printf("How many hours you will work:");
		scanf("%f",&hours);
		break;
		}
		else if(j=5)
		{
			exit(1);
			break;
		}
		else 
		{
			printf("you wrong,enter again:");
			continue;
		}
	}
	break;
	}
	
	if(hours>40)
		hours*=1.5;
	switch(j)
	{
	case 1:Allmoney=hours*A;break;
	case 2:Allmoney=hours*B;break;
	case 3:Allmoney=hours*C;break;
	case 4:Allmoney=hours*D;break;
	default:break;
	}
	if(Allmoney<300)
		tax=first_tax*Allmoney;
	else if(Allmoney>300 && Allmoney<450)
		tax=first_tax*300 + second_tax*(Allmoney-300);
	else
		tax=first_tax*300 + second_tax*150 + last_tax*(Allmoney-450);
	realmoney=Allmoney-tax;
	printf("工资总额:%.3f\t税金:%.3f\t净收入:%.3f\n",Allmoney,tax,realmoney);
}

void exit(int vaue)
{
}
//习题九
#include<stdio.h>
#define single 17850
#define head 23900
#define married 29750
#define divoiced 14875
void main()
{
	float selfmoney,tax;
	int i,j;
	for(i=1;i<40;i++)
		printf("*");
	printf("\n");
	printf("Please enter your state :\n");
	printf("1>single\t 2>head \n3>married\t 4>divoiced\t 5>quit\n");
	for(i=1;i<40;i++)
		printf("*");
	printf("\n");
	while(1)
	{
		scanf("%d",&j);
		if(j==5)
			break;
		switch(j)
		{
		case 1:
			{
				printf("enter your money:");
				scanf("%f",&selfmoney);
				if(selfmoney<=single)
					tax=selfmoney*0.15;
				else
					tax=single*0.15 + (selfmoney-single)*0.28;
			};break;
		case 2:
			{
				printf("enter your money:");
				scanf("%f",&selfmoney);
				if(selfmoney<=head)
					tax=selfmoney*0.15;
				else
					tax=head*0.15 + (selfmoney-head)*0.28;
			};break;
		case 3:
			{
				printf("enter your money:");
				scanf("%f",&selfmoney);
				if(selfmoney<=married)
					tax=selfmoney*0.15;
				else
					tax=married*0.15 + (selfmoney-head)*0.28;
			};break;
		case 4:
			{
				printf("enter your money:");
				scanf("%f",&selfmoney);
				if(selfmoney<=divoiced)
					tax=selfmoney*0.15;
				else
					tax=divoiced*0.15 + (selfmoney-head)*0.28;
			};break;
		default:printf("wrong data,enter again");
			continue;
		}
		printf("selfmoney:%.2f\t tax:%.2f",selfmoney,tax);
	}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值