C++编程题,各位高手帮解下

来源:百度知道 编辑:UC知道 时间:2024/05/09 03:22:30
6、 有一个函数
x -5<x<0
Y= x-1 x=0
x+1 0<x<10
用if语句编写程序要求输入x的值,输出y的值。

#include <iostream.h>
#include<math.h>
void main()
{
cout<<"pls input the value of x"<<endl;
int x,y;
cin>>x;
if(x<0&&x>-5) y=x;
else if(x==0) y=x-1;
else if(x>0&&x<10) y=x+1;
else ;
cout<<"the value of y is"<<y<<endl;

}

int x,y;
x = cin>>x;
if(-5<x&&x<0)
cout<<y = x;
else{ if(x == 0) cout<<y = x-1;
else if(x<10&&x>0) cout<<y = x+1;
}
把这个添main函数里就可以了。