heat index program attached

Gregory Nowak greg at romuald.net.eu.org
Wed Jun 9 23:16:39 EDT 2004

Hash: SHA1

Hi all.

It looks like the list is silently dropping messages with attachments
again, so I'm sending the below for the third time. I'll post the code
at the bottom of the message, though am not sure how it will come
through in the message body. If anyone would like an attachment, feel
free to drop me a line.

It looks like my previous message didn't make it to the list, so I'm

If anyone is interested, I'm attaching my heat index calculator
program. It accepts temperature and relative humidity on the
command-line, and will prompt if one or both are not given. If you
would rather have the program display an exact unrounded result,
uncomment the appropriate line towards the bottom of the main
function, and comment out the line above it.

To compile it, run:

g++ -o hi hi.cpp

Have fun.


 ---cut here---

/* Program for calculating heat index by Greg Nowak <greg at romuald.net.eu.org>.
Heat index formula taken from http://www.usatoday.com/weather/whicalc.htm */
// June 09, 2004

#include <iostream>
#include <cstdlib>
#include <cmath>
using namespace std;

double calc_hi (double, double);

main (int argc, char *argv[])
  double temp;
  double humidity;
  double result;
  result = temp = humidity = 0.0;

  if (argc == 1)
      cout <<
	"\nProgram for calculating heat index by Greg Nowak <greg at romuald.net.eu.org>.\n";
      cout << "\nNo command line arguments found.\n";
      cout <<
	"In the future, you may pass temperature in Fahrenheit, and relative humidity, in percent, without the percent\n"
	<< "sign as arguments.\n\n";

      cout << "Please enter the temperature in Fahrenheit:\n";
      cin >> temp;
      cout <<
	"\nPlease enter the relative humidity, in percent, without the percent sign (E.G. 65):\n";
      cin >> humidity;

  else if (argc == 2)
      cout <<
	"Please enter the relative humidity, in percent, without the percent sign (E.G. 65):\n";
      cin >> humidity;
      temp = atof (argv[1]);

      temp = atof (argv[1]);
      humidity = atof (argv[2]);

  result = round (calc_hi (temp, humidity));

// uncomment the line below to get an exact result without rounding
// result = calc_hi (temp, humidity);

  cout << "\nThe heat index is " << result << " degrees Fahrenheit.\n\n";

  return 0;

calc_hi (double t, double h)
// If anything other then numerical values and/or a period is passed to either argument of this function, the resulting return value is undefined.

  double result = -42.379;
  result += 2.04901523 * t;
  result += 10.14333127 * h;
  result -= 0.22475541 * t * h;
  result -= 6.83783 * pow (10.0, -3.0) * pow (t, 2.0);
  result -= 5.481717 * pow (10.0, -2.0) * pow (h, 2.0);
  result += 1.22874 * pow (10.0, -3.0) * pow (t, 2.0) * h;
  result += 8.5282 * pow (10.0, -4.0) * t * pow (h, 2.0);
  result -= 1.99 * pow (10.0, -6.0) * pow (t, 2.0) * pow (h, 2.0);
  return result;

- ---cut here---

- -- 
Free domains: http://www.eu.org/ or mail dns-manager at EU.org

Version: GnuPG v1.2.3 (GNU/Linux)


More information about the Speakup mailing list