Trying to write the wind chill factor equation in C++, and am having trouble with my equation and return value.
this is the function where the error comes up.
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;
}
Edit: (Ed.) after fixing the function following advice given in answers, new errors crop up:
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;
}
I know there are two things I’m doing wrong I just don’t know how to fix them. Obviously its the “^” and my return value. how would I create a square from 0.16 for windspeed?
And how would I create a correct windindex return value?
These are my errors
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'
While you haven’t included the error message(s) the compiler gives (which you should always do), here are the errors I see:
voidfunctions are functions that don’t return anything, also known as “procedures” in some other programming languages. Because you want to return real numbers, you may want to usefloat(there are alsodoubleandlong double, but in everyday use,floatis often precise enough).intbutfloatintto store intermediate results, significant information might get lost (when assigning real types to integral types, the fractional part is discarded); so instead ofint, usefloat^is the bitwise exclusive-or operator in C++. The power function is a library function in C++, namelystd::pow(x,y)from thecmathheadera = a + something,a = a - something,a = a * somethinganda = a / somethingcan be simplified toa += something, and likewise for the others1.0indicates adoublevalue, and a literal in the form1.0findicates afloatvalueSo, taking those points into account, this might better suit what you want:
Note that because of operator precedence,
*and/are evaluated before+and-, so your parentheses weren’t needed.