第二个if里应该是
if(a>150&&a<=400)
by chenxuwen @ 2022-08-10 11:08:44
@[fuhn](/user/746367)
by chenxuwen @ 2022-08-10 11:09:45
@[chenxuwen](/user/547841) 不用,他有
```cpp
else
```
改成这样就行:
```cpp
#include<iostream>
#include<iomanip>
using namespace std;
int main(){
double a;
double b;
cin>>a;
if (a>=0 && a<=150)
{
b=0.4463*a;
}
else if(a<=400)
{
b=0.4463*150+0.4663*(a-150);
}
else
{
b=150*0.4463+250*0.4663+(a-400)*0.5663;
}
printf("%.1lf",b);
return 0;
}
```
by Lovely_Chtholly @ 2022-08-10 11:11:07
确实,楼上正解
by chenxuwen @ 2022-08-10 11:13:13
(其实第一个
```cpp
if
```
好像也不用判断
```cpp
a>=0
by Lovely_Chtholly @ 2022-08-10 11:17:22
@[chenxuwen](/user/547841) 感谢大佬
by fuhn @ 2022-08-10 11:23:41
@[Lovely_Chtholly](/user/744960)
明白了 十分感谢大佬Thanks♪(・ω・)ノ
by fuhn @ 2022-08-10 11:25:51
```cpp
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
if(n<=150) cout<<fixed<<setprecision(1)<<n*0.4463;
if(n<=400&&n>150) cout<<fixed<<setprecision(1)<<150*0.4463+(n-150)*0.4663;
if(n>400) cout<<fixed<<setprecision(1)<<150*0.4463+250*0.4663+(n-400)*0.5663;
return 0;
}
//这样更短
```
by Zhengxb2010 @ 2022-08-13 14:56:30