C语言小实战开发——计算工资收益

优化前

#include 

int main() {
    int salary = 0;//记录工资
    int pay = 0;//税后工资 
    /*
    接收输入 
    */ 
    printf("请输入工资:") ;
    scanf("%d",&salary) ;
    
    /*
    计算 
    */
    if(salary < 5000) {
        pay = salary;
    }else if(salary < 8000){
        int tax =(salary - 5000)*0.1;
        pay = salary - tax;
    }else if(salary < 10000){
        int tax = (salary - 8000)*0.15+3000*0.1;
        pay = salary - tax;
    }else{
        int tax = (salary - 10000)*0.2 + 2000*0.15 + 3000*0.1;
        pay = salary - tax;
    }
    printf("到手工资:%d",pay);
    return 0;
}

优化后

#include 

int main() {
    int salary = 0;//记录工资
    int tax= 0;//税
    /*
    接收输入 
    */ 
    printf("请输入工资:") ;
    scanf("%d",&salary) ;
    
    /*
    计算 
    */
    if(salary < 5000) {
        tax = 0;
    }else if(salary < 8000){
        tax =(salary - 5000)*0.1;   
    }else if(salary < 10000){
            tax = (salary - 8000)*0.15+3000*0.1;
    }else{
            tax = (salary - 10000)*0.2 + 2000*0.15 + 3000*0.1;
    }
    printf("到手工资:%d",salary-tax);
    return 0;
}

为了保障程序的准确性应当及时测试程序,而且程序是在编写的过程中不断优化的。

你可能感兴趣的:(C语言小实战开发——计算工资收益)