可以运行,但是只能算第三个,而且为什么括号后加分号才能运行

img


#include<iostream>
using namespace std;
int main()
{
    double x,y;
    cout<<"请输入X的值:";
    cin>>x;
    if(x<0)
    {
        y=x*x;
    }
    else if(x>=0&&x<1)
    {
        y=2.5*x-1;
    }
    else if(x>=1)
    {
        y=3*x+1;
    }
    cout<<"y="<<y<<endl;
    return 0;
}

if后面要加大括号括起来,最后的else不用加条件,或者也改成else if.