程序代码:
#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 ); }