Your comments don't tell the reader anything that the code doesn't. Add comments to show what the functions do. Also put a comment at the top of the program to say what it does. None of these need to be elaborate.
Line 5: It's bad form to include the entire std namespace and it only takes a few minutes to include just the names you need. I removed this and in about 2 minutes had the code compiling again with:
1 2 3 4 5
|
using std::cin;
using std::cout;
using std::endl;
using std::pow;
using std::system;
|
Line 9: Use references for output parameters because it's much harder to pass a null reference than it is to pass a null pointer.
Line 26. Since there is only one output, WindChill should return the windchill rather than setting an output parameter to it. That way you can use the result in an expression. Also since you aren't setting t and v, and because they are small, there's no need to pass them by reference.
Line 31. Maybe provide a reference to the formula.
Line 36: Same comment as line 26
Lines 53 & 54: Don't use endl unless you really need to flush the stream. Flushing is expensive.
By changing HeatIndex and Windchill to functions, main() gets a lot simpler:
1 2 3 4 5 6 7 8 9
|
int main()
{
int v, t, r;
Input(v, t, r);
cout << "The Windchill is roughly: " << Windchill(t,v) << " degrees.\n";
cout << "The Heat Index is roughly: " << HeatIndex(t,r) << '\n';
return 0;
}
|
Putting it all together:
// Program to compute the windchill and heat index from temperature,
// wind speed and relative humidity
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
#include <ostream>
#include <iostream>
#include <string>
#include <cmath>
using std::cin;
using std::cout;
using std::endl;
using std::pow;
using std::system;
void Input(int &windSpeed, int &temp, int &relativeHumidity)
{
cout << "Please type in the wind speed in mph: " << endl;
cin >> windSpeed;
cout << "Please type in the temperature degrees Farenheit: " << endl;
cin >> temp;
cout << "Please type in the Relavtive Humidity: " << endl;
cin >> relativeHumidity;
}
// calculate the heat index from temperature t(degrees F) and windspeed v(MPH)
double Windchill(int t, int v)
{
double result = 35.74 + 0.6215 * t - 35.75 * pow(v, 0.16) + 0.4275 * t * pow(v, 0.16);
return result;
}
// compute heat index from temperature t(degrees F) and relative humidity (0-100)
double HeatIndex(int t,int r)
{
double Hindex = (-42.379 + 2.04901523*t + 10.14333127*r -
.22475541*t*r - .00683783*t*t - .05481717*r*r +
.00122874*t*t*r + .00085282*t*r*r - .00000199*t*t*r*r);
return Hindex;
}
int main()
{
int v, t, r;
Input(v, t, r);
cout << "The Windchill is roughly: " << Windchill(t,v) << " degrees.\n";
cout << "The Heat Index is roughly: " << HeatIndex(t,r) << '\n';
return 0;
}
|
This code alone would not be enough for me to recommend you for an internship. The comments I've given are one reason, but also because the code is very simple. It doesn't demonstrate very much of the language. There are no classes, no loops, not even an if statement. I suggest that you write something more intricate.