I had to do this program which calculates wind chill factor for my homework.
2 Problems:
-the answer is supposed to have 4 numbers after the decimal but it is just coming out as an integer with no decimal points even though I used setprecision(4)?
-the answer i am getting is not what the prof's answer was on our handout...
W= 33 – ((10√v – v + 10.5)(33-t))/23.1
is the equation, where w is the windchill factor, v is wind speed and t is temperature...did I write it correctly in the code?
Thanks a bunch.
Code:
#include <iostream>
using std::cout;
using std::endl;
using std::cin;
#include <cmath>
#include <iomanip>
using std::fixed;
using std::setprecision;
int windchill(double, double);
int main()
{
double wind, temp;
cout<<"Please enter the wind speed: ";
cin>>wind;
cout<<"Please enter the temperature: ";
cin>>temp;
while (temp>10)
{
cout<<"The temperature should be less than 10. Try again: ";
cin>>temp;
}
cout<<"The wind chill index is "<<setprecision(4)<<fixed<<windchill(wind,temp)<<endl;
return 0;
}
int windchill(double v, double t)
{
int w;
w=33-(((10*sqrt(v)-v+10.5)*(33-t))/23.1)<<endl;
return w;
}