80,求助!

P1422 小玉家的电费

zengziyuezzy @ 2023-08-01 20:52:18

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    double s;
    cin >> n;
    if(n <= 150) 
    {
        s = 0.4463 * n;
    }
    if(n >= 151 && n <= 400) 
    {
        s = 0.4463 * 150 + 
        (n - 150) * 0.4663;
    }
    else 
    {
        s = 0.4463 * 150 + (400 - 150) * 0.4663 
        +(n - 400) * 0.5663;
    }
    printf("%.1f",s);
    return 0;
}

by QZXJZ @ 2023-08-01 21:00:57

逻辑上有错误,最后的这个else包括 n \leq 150n \geq 401的部分


by dienter @ 2023-08-01 21:02:41

第二个if改为else if就好了


by dienter @ 2023-08-01 21:02:49

@zengziyuezzy


by yzm0325 @ 2023-08-01 21:03:02

楼上正解


by zengziyuezzy @ 2023-08-01 21:04:47

对了,谢谢!@QZXJZ @dienter


|