Nov 4, 2013 at 6:51am UTC
This programm calculates the wind chill index using user-entered values of air temperature and wind speed. My question is why the program does not execute my if-else statement after it ask for the user inputs.
I put the if else statement because the formula is only valid for wind speeds above 4.8 km/h. For wind speeds between 0 and 4.8 km/h, the wind chill is equal to the input temperature.
***Please Help****Thank you in advance
// include necessary libraries
#include <iostream>
#include <cmath>
using namespace std;
// Function Prototypes
double wind_chill_index (double, double);
void wind_chill_effects (double, double);
//This programm calculates the wind chill index using user-entered values of air temperature and wind speed.
int main ()
{
//local variables to store user inputs
double temp;
double wind_speed;
//local variable to store the calculation
double wind_chill= 0.0;
double a=0.0, b=0.0;
cout << "Please enter the TEMPERATURE (Celcius) and WIND SPEED (km/h):";
cin >> temp >> wind_speed;
if (wind_speed > 4.8)
{
wind_chill = wind_chill_index (temp,wind_speed);
wind_chill_effects (a, b);
}
else
{
wind_chill = temp;
wind_chill_effects (a, b);
}
return 0;
}
//Function definition
double wind_chill_index (double T, double V)
{
double WC;
WC = 13.12 + (0.6215 * T) - (11.37 * (pow(V, 0.16))) + (0.3965 * (T * (pow (V, 0.16))));
return WC;
}
void wind_chill_effects (double a, double b)
{
double wind_chill;
if ( wind_chill >= - 60)
{
cout << "Exposed skin may freeze in under 2 minutes." << "The wind chill is:" << wind_chill_index (a,b) << endl;
}
else if (wind_chill >= -45 )
{
cout << "Exposed skin may freeze within minutes."<< "The wind chill is:" << wind_chill_index (a,b) << endl;
}
else if (wind_chill >= -25 )
{
cout << "Risk of skin freezing (frostbite)." << "The wind chill is:" << wind_chill_index (a,b) << endl;
}
else if (wind_chill >= 0 )
{
cout << "Discomfort" <<"The wind chill is:" << wind_chill_index (a,b) << endl;
}
else
{
cout << "No destruction";
}
}
Last edited on Nov 4, 2013 at 6:56am UTC
Nov 4, 2013 at 7:13am UTC
you declared wind_chill twice
Last edited on Nov 4, 2013 at 7:20am UTC