#include<stdio.h>
#define single_dog 17850
#define the_owner 23900
#define married 29750
#define divorce 14875
int main(void)
{
float tax,s;
char classes;
printf("A:single dog;\tB:head of a household;\nC:married a total of;\tD:break a marriage;\n");
printf("Please chose your classes and enter A--B:");
classes = getchar();
if (classes == 'A')
goto single;
else if (classes == 'B')
goto household;
else if (classes == 'C')
goto have_married;
else if (classes == 'D')
goto break_married;
else
printf("input error!");
single:
{
printf("Please enter your salary now:");
scanf_s("%f", &s);
if (s <= single_dog)
tax = s * 0.15;
else tax = single_dog + (s - single_dog) * 0.28;
}
household:
{
printf("Please enter your salary now:");
scanf_s("%f", &s);
if (s <= the_owner)
tax = s * 0.15;
else tax = the_owner + (s - the_owner) * 0.28;
}
have_married:
{
printf("Please enter your salary now:");
scanf_s("%f", &s);
if (s <= married)
tax = s * 0.15;
else tax = married + (s - married) * 0.28;
}
break_married:
{
printf("Please enter your salary now:");
scanf_s("%f", &s);
if (s <= divorce)
tax = s * 0.15;
else tax = divorce + (s - divorce) * 0.28;
}
printf("So we can konow your tax is %f", tax);
return 0;
}
在每个标签里面,计算完税收之后,用一个goto跳转到最后打印税收那里即可,修改如下:
#include<stdio.h>
#define single_dog 17850
#define the_owner 23900
#define married 29750
#define divorce 14875
int main(void)
{
float tax,s;
char classes;
printf("A:single dog;\tB:head of a household;\nC:married a total of;\tD:break a marriage;\n");
printf("Please chose your classes and enter A--B:");
classes = getchar();
if (classes == 'A')
goto single;
else if (classes == 'B')
goto household;
else if (classes == 'C')
goto have_married;
else if (classes == 'D')
goto break_married;
else
printf("input error!");
single:
{
printf("Please enter your salary now:");
scanf("%f", &s);
if (s <= single_dog)
tax = s * 0.15;
else tax = single_dog + (s - single_dog) * 0.28;
goto printTax;
}
household:
{
printf("Please enter your salary now:");
scanf("%f", &s);
if (s <= the_owner)
tax = s * 0.15;
else tax = the_owner + (s - the_owner) * 0.28;
goto printTax;
}
have_married:
{
printf("Please enter your salary now:");
scanf("%f", &s);
if (s <= married)
tax = s * 0.15;
else tax = married + (s - married) * 0.28;
goto printTax;
}
break_married:
{
printf("Please enter your salary now:");
scanf("%f", &s);
if (s <= divorce)
tax = s * 0.15;
else tax = divorce + (s - divorce) * 0.28;
goto printTax;
}
printTax:
printf("So we can konow your tax is %f", tax);
return 0;
}