#include #include // for setw #include // for sqrt using namespace std; // Owen Astrachan // nested loops to print wind-chill chart // // idea: Programming with Class by Kamin and Reingold, McGraw-Hill // formula for wind-chill from // UMAP Module 658, COMAP, Inc., Lexington, MA 1984, Bosch and Cobb double WindChill(double temperature, double windSpeed); int main() { const int WIDTH = 5; const int MIN_TEMP = -40; const int MAX_TEMP = 50; const string LABEL = "deg. F: "; int temp,wind; // print column headings cout << LABEL; for(temp = MAX_TEMP; temp >= MIN_TEMP; temp -=10) { cout << setw(WIDTH) << temp; } cout << endl << endl; // print table of wind chill temperatures for(wind = 0; wind <= MAX_TEMP; wind += 5) // row heading { cout << wind << " mph:\t"; for (temp = MAX_TEMP; temp >= MIN_TEMP; temp -= 10) // print the row { cout << setw(WIDTH) << int(WindChill(temp,wind)); } cout << endl; } return 0; } double WindChill(double temperature, double windSpeed) // precondition: temperature in degrees Fahrenheit // postcondition: returns wind-chill index/comparable temperature { if (windSpeed <= 4) // low wind, temperature unaltered { return temperature; } else if (windSpeed <= 45) // high wind { return 91.4 - (10.45 + 6.69*sqrt(windSpeed) - 0.447 * windSpeed) * (91.4 - temperature)/22.0; } else { return (1.6 * temperature - 55.0); } }