# Thread: Void function not printing to screen. Plz Help!!!

1. ## Void function not printing to screen. Plz Help!!!

Hi, I am supposed to write code for a program that calculates the wind chill index based on the temperature and wind speed entered by the user. Then I have to use a void function which has to "cout" the effect based on the windchill. I can get the program to output the windchill but can't get the void function to work. Please help. Thanks!

Code:
```#include <iostream>
#include <cmath>

using namespace std;

double windchill_calculator(double temperature, double windspeed);
void effect(double windchill);

int main()
{
double w;
double temperature;
double windspeed;

do
{
cout << "Enter the air temperature in degree Celsius: ";
cin >> temperature;

cout << "Enter the wind speed in kilometres per hour (km/h): ";
cin >> windspeed;

if (windspeed < 0)
cout << "The windspeed must be greater or equal to 0"<< endl<< endl;

} while (windspeed < 0);

if (windspeed > 4.8)
w = windchill_calculator(temperature, windspeed);

else if (windspeed >= 0 && windspeed <= 4.8)
w = temperature;

cout << "The wind chill index is " << w << endl;

effect(w);

}

double windchill_calculator(double temperature, double windspeed)
{
double windchill = 13.12 + (0.6215*temperature) - (11.37*(pow(windspeed,0.16))) + (0.3965*temperature*pow(windspeed,0.16));
return windchill;
}

void effect(double windchill)
{
if (windchill >= 0 && windchill < -25)
{
cout<< "Discomfort"<< endl;
}
else if (windchill >= -25 && windchill < -45)
{
cout<< "Risk of skin freezing (frostbite)"<< endl;
}
else if (windchill >= -45 && windchill < -60)
{
cout<< "Exposed skin may freeze within minutes"<< endl;
}
else if (windchill >= 60)
{
cout<< "Exposed skin may freeze in under 2 minutes"<< endl;
}

return;
}```

2. How does it not work?

(In this case I can see why it does not work, but you should get into the habit.)

3. Sorry. This is the out put i get when i enter the values -30 and 50 for temperature and windspeed, respectively.

Enter the air temperature in degree Celsius: -30
Enter the wind speed in kilometres per hour (km/h): 50
The wind chill index is -49.0299

4. In other words, effect does not seem to print any effect at all, even when it should have printed "Exposed skin may freeze within minutes".

Here's a maths quiz: pick a real number that is greater than or equal to 0, and less than -25. Done? What number did you pick?

5. I don't get what you mean...

6. Originally Posted by c++help
I don't get what you mean...
Basically, you are specifying your windchill range wrongly. If we draw a real number line:
Code:
```.          -25                0
<-----------|-----------------|--------------->
<-----------|                 |--------------->
Region A                         Region B```
The only real numbers that satisfy your condition are those that exist in region A and B simultaneously. No such real numbers exist.

A typical way to do this is to start from one extreme first. So, if windchill <= -60, print "Exposed skin may freeze in under 2 minutes". Else, if windchill <= -45, print "Exposed skin may freeze within minutes". This immediately caters for the case where windchill == -50, because -50 is not <= -60, but it is <= -45.