试图用 C++ 编写风寒因子方程,但我的方程和返回值有问题。
这是出现错误的函数。
void eqfunction(int temperature, int windspeed){
int windindex;
windindex = 35.74 + (0.6215 * temperature);
windindex = windindex - (35.75 * windspeed^0.16);
windindex = windindex + ((0.4275 * temperature)*windspeed^0.16);
return windindex;
}
编辑:(Ed.)在按照答案中给出的建议修复功能后,会出现新的错误:
float windChillFactor(float temperature, float windspeed){
float windindex = 35.74f + 0.6215f * temperature;
windindex -= 35.75f * std::pow(windspeed, 0.16f);
windindex += 0.4275f * temperature * std::pow(windspeed, 0.16f);
return windindex;
}
我知道有两件事我做错了,我只是不知道如何解决它们。显然它是“^”和我的返回值。我将如何从 0.16 为风速创建一个正方形?我将如何创建正确的 windindex 返回值?
这些是我的错误
1>c:\users\ryan\desktop\final.cpp\final.cpp\final project.cpp(18):
warning C4244: 'argument' : conversion from 'int' to 'float',
possible loss of data
1>c:\users\ryan\desktop\final.cpp\final.cpp\final project.cpp(18):
warning C4244: 'argument' : conversion from 'int' to 'float',
possible loss of data
1>c:\users\ryan\desktop\final.cpp\final.cpp\final project.cpp(18):
error C2440: '=' : cannot convert from 'void' to 'int'
1> Expressions of type void cannot be converted to other types
1>c:\users\ryan\desktop\final.cpp\final.cpp\final project.cpp(22):
error C2556: 'float eqfunction(float,float)' : overloaded function differs
only by return type from 'void eqfunction(float,float)'
1> c:\users\ryan\desktop\final.cpp\final.cpp\final project.cpp(6) :
see declaration of 'eqfunction'
1>c:\users\ryan\desktop\final.cpp\final.cpp\final project.cpp(22):
error C2371: 'eqfunction' : redefinition; different basic types
1> c:\users\ryan\desktop\final.cpp\final.cpp\final project.cpp(6) :
see declaration of 'eqfunction'