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

This is a discussion on Void function not printing to screen. Plz Help!!! within the C++ Programming forums, part of the General Programming Boards category; Hi, I am supposed to write code for a program that calculates the wind chill index based on the temperature ...

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    5

    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. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,794
    How does it not work?

    (In this case I can see why it does not work, but you should get into the habit.)
    Last edited by laserlight; 11-06-2011 at 01:15 AM.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Nov 2011
    Posts
    5
    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. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,794
    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?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Nov 2011
    Posts
    5
    I don't get what you mean...

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,794
    Quote 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.
    Last edited by laserlight; 11-06-2011 at 01:10 AM.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why is this not printing to screen?
    By lilbo4231 in forum C Programming
    Replies: 2
    Last Post: 03-07-2011, 02:10 PM
  2. printing in screen
    By imagetvr in forum C++ Programming
    Replies: 2
    Last Post: 08-16-2008, 10:35 AM
  3. Printing \n on the screen in C
    By swgh in forum C Programming
    Replies: 4
    Last Post: 05-18-2007, 03:52 PM
  4. fprintf in void function Not Printing
    By thetinman in forum C Programming
    Replies: 5
    Last Post: 10-17-2006, 05:13 PM
  5. Passing a variable in void to another void function
    By stevedawg85 in forum C++ Programming
    Replies: 5
    Last Post: 05-05-2006, 06:17 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21