作业课后题不太懂大佬能看看吗
允许用户键入个人年收入(使用fgets和atoi),然后根据下表使用if-else语句打印收入组年收入低于0是不可能的。如果输入值低于0,请打印错误信息。然后,按下表计算个人所得税
请注意这是边际税率。这意味着,如果所得为250,000,则应按(10-2万)×10%计算所得税+ (200,000-100,000)*20% + (250,000-200,000)*30%
#include <stdio.h> int main( void ) { int income; if( scanf("%d",&income) != 1 ) { puts( "输入非整型" ); return 1; } if( income < 0 ) { puts( "收入为负" ); return 0; } const char* group; double tax; if( income <= 20000 ) { group = "Low"; tax = 0; } else if( income <= 100000 ) { group = "Lower-middle"; tax = (income-20000)*0.1; } else if( income <= 200000 ) { group = "Upper-middle"; tax = (100000-20000)*0.1 + (income-100000)*0.2; } else { group = "High"; tax = (100000-20000)*0.1 + (200000-100000)*0.2 + (income-200000)*0.3; } printf( "Income group: %s\n", group ); printf( "Income tax: %.2f\n", tax ); }