这道C++题怎么做?

就是这道题,用C++做
img

#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
    int n=0;
    double x=0;
    cin>>n;
    if(n>=0 && n<=300)
        x=0.5*n;
    else if(n>300 && n<=400)
        x=0.5*300+(n-300)*0.55;
    else if(n>400)
        x=0.5*300+0.55*100+0.6*(n-400);
    printf("%.3lf",x);
    return 0;
}

有帮助望采纳,谢谢!

#include <cstdio>

int main()
{
    int n;
    double S;
    scanf("%d",&n);
    if (n >= 0 && n <= 300)
    {
        S = 0.5 * n;
    }
    else if (n >= 301 && n <= 400)
    {
        S = 150 + (n-300) * 0.55;
    }
    else
    {
        S = 150 + 55 + (n- 400) * 0.6;
    }
    printf("%.3f",S);
    return 0;
}