编写一程序,让用户指定缴纳的税金种类及应纳税收入,自动计算税金。
类别 | 税金 |
单身 | 17850美元按15%计,超出部分按28%计 |
户主 | 23900美元按15%计,超出部分按28%计 |
已婚,共有 | 29750美元按15%计,超出部分按28%计 |
已婚,离异 | 14875美元按15%计,超出部分按28%计 |
如:一位工资20000美元的单身人士,应缴纳的税费为0.15*7850+0.28*(20000-17850)美元。
代码:
#include<stdio.h>
#define SINGLE 17850
#define HOLDER 23900
#define MARRY 29750
#define DIVORCE 14875
#define BASE_TAX 0.15
#define EXTRA_TAX 0.28
int main(void)
{
char type;
float salary;
float tax, salary_taxed;
do
{
printf("Select tax type. There four type:\n");
printf("1)single 2)house holder 3)married 4)divorced 5)quit:\n");
scanf("%c", &type);
switch (type)
{
case '1':/*单身*/
printf("enter your salary:");
scanf("%f", &salary);
if (salary <= SINGLE)
{
tax = salary * BASE_TAX;
salary_taxed = salary - tax;
}
else
{
tax = salary * BASE_TAX + (salary - SINGLE) * EXTRA_TAX;
salary_taxed = salary - tax;
}
printf("your salary is %.2f, tax is %.2f, after tax salary is %2f\b\n", salary, tax, salary_taxed);
break;
case '2':/*户主*/
printf("enter your salary:");
scanf("%f", &salary);
if (salary <= HOLDER)
{
tax = salary * BASE_TAX;
salary_taxed = salary - tax;
}
else
{
tax = salary * BASE_TAX + (salary - HOLDER) * EXTRA_TAX;
salary_taxed = salary - tax;
}
printf("your salary is %.2f, tax is %.2f, after tax salary is %2f\b\n", salary, tax, salary_taxed);
break;
case '3':/*已婚,共有*/
printf("enter your salary:");
scanf("%f", &salary);
if (salary <= MARRY)
{
tax = salary * BASE_TAX;
salary_taxed = salary - tax;
}
else
{
tax = salary * BASE_TAX + (salary - MARRY) * EXTRA_TAX;
salary_taxed = salary - tax;
}
printf("your salary is %.2f, tax is %.2f, after tax salary is %2f\b\n", salary, tax, salary_taxed);
break;
case '4':/*离异*/
printf("enter your salary:");
scanf("%f", &salary);
if (salary <= DIVORCE)
{
tax = salary * BASE_TAX;
salary_taxed = salary - tax;
}
else
{
tax = salary * BASE_TAX + (salary - DIVORCE) * EXTRA_TAX;
salary_taxed = salary - tax;
}
printf("your salary is %.2f, tax is %.2f, after tax salary is %2f\b\n", salary, tax, salary_taxed);
break;
case '5':
break;
default:printf("wrong type.retry.\n");
}
} while (type != '5');
printf("done\n");
return 0;
}