80分!求助!

P1422 小玉家的电费

Wen_Yun @ 2023-04-16 09:52:46


using namespace std;
int main(){
    int a;
    double b=0;//双精度小数型 
    cin>>a;
    if(a<=150){//判断小于等于150 
        b=a*0.4463;
    }
    if(a>=151&&a<=400){//大于150小于等于400 
        b=150*0.4463+(a-150)*0.4663;
    }else{//不是前两种一定就是大于400 
        b=150*0.4463+250*0.4663+(a-400)*0.5663;
    }
    printf("%.1lf",b); 
    return 0;
    }

by Wen_Yun @ 2023-04-16 10:25:24

回复啊


by congege @ 2023-04-19 12:34:12

@Wangyuqi123 想一下第二个if 是不是忘记小于151的时候 else也能进去

 if(a<=150){//判断小于等于150 
        b=a*0.4463;
    }else if(a>=151&&a<=400){//大于150小于等于400 
        b=150*0.4463+(a-150)*0.4663;
    }else{//不是前两种一定就是大于400 
        b=150*0.4463+250*0.4663+(a-400)*0.5663;
    }

|