c++分段函数实现

2024-11-07 13:47:07
推荐回答(3个)
回答1:

修改好了,在C++里面判断400
#include
#include
using namespace std;

double countPAR(double P,double gn1)
{
const double NI=2000;
if(0 P=gn1/NI+0.3;
else if(400 P=gn1/NI+0.2;
else if(800<=gn1&&gn1<=1200)
P=gn1/NI+0.1;
else if(1200 P=gn1/NI;
else
P=gn1/NI-0.1;
return P;
}
int main()
{
double gn;
double PAR=0;
cout<<"please enter gn:";
cin>>gn;
cout< return 0;
}

回答2:

//#include
#include
#include
using namespace std;

double countPAR(double P,int gn1)
{
const int NI=2000;
if(0 P=gn1/NI+0.3;
else
{
if(400 P=gn1/NI+0.2;
else
{
if(800<=gn1<=1200)
P=gn1/NI+0.1;
else
{
if(1200 P=gn1/NI;
else
P=gn1/NI-0.1;

}

}
}
return P;
}
int main()
{
int gn;
double PAR=0;
cout<<"please enter gn:";
cin>>gn;
countPAR(PAR,gn);
cout< return 0;
}

回答3:

我看了下
我的c++没有库文件'stdafx.h'
c:\hhjf\kj.cpp(1) : fatal error C1083: Cannot open include file: 'stdafx.h': No such file or directory
不知道你的是不是这样