Ravager Posted October 3, 2004 Share Posted October 3, 2004 (edited) Most of the code works well... #include <iostream> using namespace std; #include <cmath> void windchill (double airtemp, double windspeed, int chillindex) { if (0 >= chillindex > -25) { cout << "discomfort." << endl; return; } if (-25 >= chillindex > -45) { cout << "a risk of skin freezing (frostbite)." << endl; return; } if (-45 >= chillindex > -60) { cout << "exposed skin may freeze within minutes." << endl; return; } if (-60 >= chillindex) { cout << "exposed skin may freeze in under 2 minutes." << endl; return; } return; } int main() { double airtemp, windspeed; int chillindex; airtemp = 0; windspeed = 0; chillindex = 0; windchill (airtemp, windspeed, chillindex); chillindex = 13.12 + (0.6215 * airtemp) - (11.37 * (pow(windspeed, 0.16))) + (0.3965 * airtemp * (pow(windspeed, 0.16))); cout << "Welcome to the wind chill index program." << endl; cout << "Please enter air temperature in degrees Celcius." << endl; cin >> airtemp; cout << "Now enter the wind speed in kilometers per hour." << endl; cin >> windspeed; if (windspeed < 4.8) { cout << "Wind chill only applies to wind speeds of over 4.8km/h" << endl; return 0; } cout << "If the temperature is " << airtemp << " degrees Celcius, and the wind speed is " << windspeed << " kilometers per hour..." << endl; cout << "The wind chill index will be " << chillindex << "." << endl; cout << "This could mean " << windchill << endl; return 0; } but in my output, I get something like this: This could mean 0041FA8C discomfort and my wind chill index is always 13... the value doesn't change no matter what values I put in... Why is this happening? EDIT: UPDATED CODE Edited October 3, 2004 by Ravager Link to comment Share on other sites More sharing options...
0 Ravager Posted October 3, 2004 Author Share Posted October 3, 2004 Alright. I fixed the chillindex problem. I executed the formula a bit too early. ;) However, I still have the 0041FA8C problem... Link to comment Share on other sites More sharing options...
0 Vector9 Posted October 3, 2004 Share Posted October 3, 2004 (edited) Since you have a void function there's really no need to return anything in the function once you called it, and since you're using cout to try and print the function results, you're going to get hexadecimal code (I believe). If you fixed the chillindex problem, you could run the function like this... cout << "The wind chill index will be " << chillindex << "." << endl; cout << "This could mean "; windchill(airtemp, windspeed, chillindex); cout << endl; My code without chillindex problem fixed... #include <iostream> using namespace std; #include <cmath> void windchill (double airtemp, double windspeed, int chillindex) { if ((chillindex <= 0) && (chillindex > -25)) { cout << "discomfort." << endl; return; } if ((chillindex <= -25) && (chillindex > -45)) { cout << "a risk of skin freezing (frostbite)." << endl; return; } if ((chillindex <= 45) && (chillindex > -60)) { cout << "exposed skin may freeze within minutes." << endl; return; } if (chillindex <= -60) { cout << "exposed skin may freeze in under 2 minutes." << endl; return; } return; } int main() { double airtemp, windspeed; double chillindex; airtemp = 0; windspeed = 0; chillindex = 0; chillindex = 13.12 + (0.6215 * airtemp) - (11.37 * (pow(windspeed, 0.16))) + (0.3965 * airtemp * (pow(windspeed, 0.16))); cout << "Welcome to the wind chill index program." << endl; cout << "Please enter air temperature in degrees Celcius." << endl; cin >> airtemp; cout << "Now enter the wind speed in kilometers per hour." << endl; cin >> windspeed; if (windspeed < 4.8) { cout << "Wind chill only applies to wind speeds of over 4.8km/h" << endl; return 0; } cout << "If the temperature is " << airtemp << " degrees Celcius, and the wind speed is " << windspeed << " kilometers per hour..." << endl; cout << "The wind chill index will be " << chillindex << "." << endl; cout << "This could mean "; windchill(airtemp, windspeed, chillindex); cout << endl; return 0; } Edited October 3, 2004 by Vector9 Link to comment Share on other sites More sharing options...
0 kjordan2001 Posted October 3, 2004 Share Posted October 3, 2004 What you were doing there was printing out the address of your function instead of calling it to print out its junk. What Vector9 posted should fix it. Link to comment Share on other sites More sharing options...
0 Ravager Posted October 3, 2004 Author Share Posted October 3, 2004 Alright. I'm getting the junk now... But what's happening is that the junk value never changes either... I'm guessing it's with my order. No matter what my wind chill index is (it changes now), my program will always output "discomfort". Link to comment Share on other sites More sharing options...
0 kjordan2001 Posted October 3, 2004 Share Posted October 3, 2004 Alright. I'm getting the junk now...But what's happening is that the junk value never changes either... I'm guessing it's with my order. No matter what my wind chill index is (it changes now), my program will always output "discomfort". if (0 >= chillindex > -25) You can't do that like that. It gives the result of 0 >= chillindex and compares it to -25, which 0 and 1 (true and false, which are numbers in C) are always greater than. What you need to do is: if (chillindex <= 0 && chillindex > -25) Link to comment Share on other sites More sharing options...
0 Ravager Posted October 3, 2004 Author Share Posted October 3, 2004 Awesome! That did it. I've been getting too used to writing math down on paper. :p Thanks a lot, guys. Link to comment Share on other sites More sharing options...
Question
Ravager
Most of the code works well...
#include <iostream> using namespace std; #include <cmath> void windchill (double airtemp, double windspeed, int chillindex) { if (0 >= chillindex > -25) { cout << "discomfort." << endl; return; } if (-25 >= chillindex > -45) { cout << "a risk of skin freezing (frostbite)." << endl; return; } if (-45 >= chillindex > -60) { cout << "exposed skin may freeze within minutes." << endl; return; } if (-60 >= chillindex) { cout << "exposed skin may freeze in under 2 minutes." << endl; return; } return; } int main() { double airtemp, windspeed; int chillindex; airtemp = 0; windspeed = 0; chillindex = 0; windchill (airtemp, windspeed, chillindex); chillindex = 13.12 + (0.6215 * airtemp) - (11.37 * (pow(windspeed, 0.16))) + (0.3965 * airtemp * (pow(windspeed, 0.16))); cout << "Welcome to the wind chill index program." << endl; cout << "Please enter air temperature in degrees Celcius." << endl; cin >> airtemp; cout << "Now enter the wind speed in kilometers per hour." << endl; cin >> windspeed; if (windspeed < 4.8) { cout << "Wind chill only applies to wind speeds of over 4.8km/h" << endl; return 0; } cout << "If the temperature is " << airtemp << " degrees Celcius, and the wind speed is " << windspeed << " kilometers per hour..." << endl; cout << "The wind chill index will be " << chillindex << "." << endl; cout << "This could mean " << windchill << endl; return 0; }but in my output, I get something like this:
and my wind chill index is always 13... the value doesn't change no matter what values I put in...
Why is this happening?
EDIT: UPDATED CODE
Edited by RavagerLink to comment
Share on other sites
6 answers to this question
Recommended Posts