计算所得税tax.
#include
#define SINGLE 17850
#define HOST 23900
#define MARRIED_SHARE 29750
#define MARRIED_DIVORCE 14875
#define RATE1 0.15
#define RATE2 0.28
int main()
{
float type,pay,tax;
char ch;
while(1)
{
printf("Select the type of marriage:\n");
printf("1)SINGLE\t2)HOST\n3)MARRIED_SHARE\t4)MARRIED_DIVORCE\n");
while((ch=getchar())=='\n');continue;//滤掉回车
switch(ch)
{
case '1':type=SINGLE;break;
case '2':type=HOST;break;
case '3':type=MARRIED_SHARE;break;
case '4':type=MARRIED_DIVORCE;break;
case '5':printf("quit!\n");return 0;
default:printf("Input error.\n");continue;
}
printf("you have select %c\n",ch);
printf("input the pay:");
scanf("%f",&pay);
if(pay<=type)tax=pay*RATE1;
else tax=type*RATE1+(pay-type)*RATE2;
printf("tax is %.2f\n");
}
}
生成程序后输入1或者2其他数字,都一直在循环
printf("Select the type of marriage:\n");
printf("1)SINGLE\t2)HOST\n3)MARRIED_SHARE\t4)MARRIED_DIVORCE\n");
这两个语句?感觉getchar()有点问题,以前也有碰到这样的情况,输入完全没反应。
- 编程小白求助