C++ 我不知道';我不明白为什么这个简单的程序会输出胡言乱语? #包括 #包括 使用名称空间std; 双T; 双V; 双WC(双T,双V); 孔隙指数(双WC(双T,双V)); 内部主(空) { coutV; cout
您没有调用C++ 我不知道';我不明白为什么这个简单的程序会输出胡言乱语? #包括 #包括 使用名称空间std; 双T; 双V; 双WC(双T,双V); 孔隙指数(双WC(双T,双V)); 内部主(空) { coutV; cout,c++,function,parameters,parameter-passing,C++,Function,Parameters,Parameter Passing,您没有调用index,而是在打印它的地址。方法调用需要参数index()我想您需要的是: 要调用索引函数,需要执行以下操作: #include <iostream> #include <cmath> using namespace std; double T; double V; double WC(double T, double V); void index(double WC(double T, double V)); int main(void) {
index
,而是在打印它的地址。方法调用需要参数index()
我想您需要的是:
要调用索引函数,需要执行以下操作:
#include <iostream>
#include <cmath>
using namespace std;
double T;
double V;
double WC(double T, double V);
void index(double WC(double T, double V));
int main(void)
{
cout<<"Please enter your T followed by your V"<<endl;
cin>>T>>V;
cout<<index;
}
double WC(double, double)
{
if(V>4.8)
return 13.12+0.6215*T-11.37*pow(V,0.16)+0.3965*T*pow(V,0.16);
else
return T;
}
void index(double WC(double,double))
{
if (WC(T,V)<=0&&WC(T,V)>=-25)
{
cout<<"Discomfort";
}
if (WC(T,V)<-25&&WC(T,V)>=-45)
{
cout<<"Risk of skin freezing (frostbite)";
}
if (WC(T,V)<-45&&WC(T,V)>=-60)
{
cout<<"Exposed skin may freeze within minutes";
}
if (WC(T,V)<-60)
{
cout<<"Exposed skin may freeze in under 2 minutes";
}
}
#包括
#包括
使用名称空间std;
双T;
双V;
双WC(双T,双V);
孔隙指数(双WC(双T,双V));
内部主(空)
{
V=5.0;
T=-60.0;
//声明一个函数指针,它接受两个double并返回一个double
双人(*wcPtr)(双人,双人);
//初始化函数指针
wcPtr=&WC;
如果您没有调用索引
函数并打印出索引
函数的地址,这可能会有所帮助:详细说明Ed S
的要点:什么是T
?什么是V
?什么是WC
?您只使用一个提示符并使用inpu是什么t同时而不是提示输入提示输入?等…几乎与我的相同的措辞…顺便说一句,索引
takeargument@BryanChen当前位置我知道。你应该发布答案而不是评论。我试过了cout@user2923961:您的函数符号应该是索引(double(*f)(double,double));
,即,它接受一个指向函数的指针,该函数接受两个double并返回一个double
#include <iostream>
#include <cmath>
using namespace std;
double T;
double V;
double WC(double T, double V);
void index(double WC(double T, double V));
int main(void)
{
V = 5.0;
T = -60.0;
// declare a function pointer which accepts two doubles and returns a double
double (*wcPtr)(double, double);
// initialise function pointer
wcPtr = &WC;
cout << "Please enter your T followed by your V" << endl;
// call function pointer
index(wcPtr);
}
double WC(double T, double V)
{
if(V>4.8)
return 13.12+0.6215*T-11.37*pow(V,0.16)+0.3965*T*pow(V,0.16);
else
return T;
}
void index(double WC(double T,double V))
{
if (WC(T,V)<=0&&WC(T,V)>=-25)
{
cout<<"Discomfort";
}
if (WC(T,V)<-25&&WC(T,V)>=-45)
{
cout<<"Risk of skin freezing (frostbite)";
}
if (WC(T,V)<-45&&WC(T,V)>=-60)
{
cout<<"Exposed skin may freeze within minutes";
}
if (WC(T,V)<-60)
{
cout<<"Exposed skin may freeze in under 2 minutes";
}
}