#include<stdio.h>
#define LEVEL1 17850
#define LEVEL2 23900
#define LEVEL3 29750
#define LEVEL4 14875
#define TAX1 0.15
#define TAX2 0.28
int main(void)
{
int situation;
int income;
double tax;
printf("Enter your situation:\n1 Single\n2 House holder\n3 Married"
"\n4 Divorced\n");
while ((scanf_s("%d", &situation)) == 1)
{
if (situation < 1 || situation>4)
{
printf("Enter a correct number.");
continue;
}
printf("Enter your income:");
loop:scanf_s("%d", &income);
switch (situation)
{
case 1:
if (income <= LEVEL1)
tax = income * TAX1;
else
tax = LEVEL1 * TAX1 + (income - LEVEL1) * TAX2;
break;
case 2:
if (income <= LEVEL2)
tax = income * TAX1;
else
tax = LEVEL2 * TAX1 + (income - LEVEL2) * TAX2;
break;
case 3:
if (income <= LEVEL3)
tax = income * TAX1;
else
tax = LEVEL3 * TAX1 + (income - LEVEL3) * TAX2;
break;
case 4:
if (income <= LEVEL4)
tax = income * TAX1;
else
tax = LEVEL4 * TAX1 + (income - LEVEL4) * TAX2;
break;
default:
printf("Enter correct income.");
goto loop;
}
printf("Your tax is $%f.\nEnter next situation(input q to quit).\n", tax);
}
printf("Bye");
return 0;
}
C Primer Plus 第七章 第10题
最新推荐文章于 2024-09-15 04:17:06 发布