#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;
}
请问要输入四次这个怎么办啊?
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- a5156520 2023-01-01 19:22关注
在每个标签里面,计算完税收之后,用一个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; }
解决 无用评论 打赏 举报
悬赏问题
- ¥15 python怎么在已有视频文件后添加新帧
- ¥20 虚幻UE引擎如何让多个同一个蓝图的NPC执行一样的动画,
- ¥15 fluent里模拟降膜反应的UDF编写
- ¥15 MYSQL 多表拼接link
- ¥15 关于某款2.13寸墨水屏的问题
- ¥15 obsidian的中文层级自动编号
- ¥15 同一个网口一个电脑连接有网,另一个电脑连接没网
- ¥15 神经网络模型一直不能上GPU
- ¥15 pyqt怎么把滑块和输入框相互绑定,求解决!
- ¥20 wpf datagrid单元闪烁效果失灵