求大佬调试

B2047 分段函数

DPG_DPG123 @ 2023-07-10 11:20:22

https://www.luogu.com.cn/record/114674708

# include <iostream>
using namespace std;
double f(double x){
    if (0 <= x < 5) return -x + 2.5;
    else if (5 <= x < 10) return 2 - 1.5 * (x-3) * (x-3);
    else if (10 <= x < 20) return x / 2.0 - 1.5;
}
int main(){
    double n;
    cin >> n;
    printf("%.3lf", f(n));
    return 0;
}

by Eleveslaine @ 2023-07-10 11:24:51

@DPG_DPG123 程序里 a\le x<b 不能写成 a <= x < b。应写成 a <= x && x < b


by gjc1108 @ 2023-07-10 11:26:05

@DPG_DPG123

C++不能连着判断,你可以写x>=0&&x<5这样的


|