各位上仙,本人刚入门,写了个c primer plus的课后编程练习,但总觉着哪里有点问题,请各位上仙帮瞧瞧。
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <ctype.h>
int exec_class(int c_class,float c_money);
bool chenk_class(void);
float get_num(int num_s);
int main(){
int c_class;
float c_money;
do{
printf("所得税计算公式:/n");
printf("1):单身 2):户主 /n3):已婚共有 4):离异 (按0退出):/n");
c_class=get_num(1);
if (c_class==0) exit(1);
printf("输入工资: (按0退出):/n");
c_money=get_num(2);
if (c_money==0) exit(1);
exec_class(c_class,c_money);
}while(chenk_class()==true);
return 0;
}
bool chenk_class()
{
char ch1;
ch1=getchar();
if(ch1=='y'){
return true;
}else if(ch1=='n'){
return false;
}else {
while(ch1=getchar()!='/n');
printf("要继续么? [y/n]");
chenk_class();
}
}
float get_num(int num_s){ //获取输入的数
int input_int;
float input_flo;
char ch;
if(num_s==1){
while((scanf("%d",&input_int))!=1 || input_int<0 || input_int>4){
while (ch=getchar()!='/n')
printf("%c",ch);
printf(" 不是一个合法的数字,请重新输入.../nnotice:please intput a num like 1 2 3 4 ....(按0退出)/n ");
}
return input_int;
}else if (num_s==2){
while((scanf("%f",&input_flo))!=1 || input_flo<0){
while (ch=getchar()!='/n')
printf("%c",ch);
printf(" 不是一个合法的数字,请重新输入.../nnotice:please intput a num like 10 25 74 ....(按0退出)/n ");
}
return input_flo;
}
}
int exec_class(int c_class,float money_total){
float money_end=0;
switch(c_class)
{
case 1:
if (money_total>17850){
money_end=17850*0.15+(money_total-17850)*0.28;
printf("您是单身,收入为%d",money_total);
printf("税金为:%.2f/n",money_end);
}
if (money_total<=17850){
printf("您是单身,收入为%f",money_total);
money_end=money_total*0.15;
printf("税金为:%.2f/n",money_end);
}
break;
case 2:
if (money_total>23900){
money_end=23900*0.15+(money_total-23900)*0.28;
printf("您是户主,收入为%f",money_total);
printf("税金为:%.2f/n",money_end);
}
if (money_total<=23900){
money_end=money_total*0.15;
printf("您是户主,收入为%f",money_total);
printf("税金为:%.2f/n",money_end);
}
break;
case 3:
if (money_total>29750){
money_end=29750*0.15+(money_total-29750)*0.28;
printf("您是已婚共有,收入为%f",money_total);
printf("税金为:%.2f/n",money_end);
}
if (money_total<=29750){
money_end=money_total*0.15;
printf("您是已婚共有,收入为%f",money_total);
printf("税金为:%.2f/n",money_end);
}
break;
case 4:
if (money_total>14875){
money_end=14875*0.15+(money_total-14875)*0.28;
printf("您是离异,收入为%f",money_total);
printf("税金为:%.2f/n",money_end);
}
if (money_total<=14875){
money_end=money_total*0.15;
printf("您是离异,收入为%f",money_total);
printf("税金为:%.2f/n",money_end);
}
break;
default:break;
}
return 0;
}